🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #8759

Re: How I read a variable?

#8759
From: Hartmut
Date: Fri, 02 Mar 2001 10:11
34 lines
2081 bytes
Gustavo,

I don't know about Pascal's read() - 10 years ago for me, sorry -
but I guess you want to reach the content of a DOS environment variable
defined like "SET  WINDIR=C:\WINNT".
You could do it like this:

String tempfile = "c:\\temp\\x.txt";
Runtime.getRuntime().exec( "command.com /c set > " + tempfile );
File file = new File( tempfile );
InputStream input = new FileInputStream( file );
Properties prop = new Properties();
prop.load( input );
input.close();
file.deleteOnExit();

This all must be in a try-Block and catch IOException.

You can get the content of each DOS variable now like prop.getProperty(
"WINDIR" );

Just try with the case sensivity. Your variable might be defined as "windir"
or "Windir" etc. - DOS doesn't care, but Properties class does.

Of course - from Java sight I must say this is a very ugly solution!
But for DOS' and Windows' environment variables that might be adequate. :-)
This code is not portable, and you need a temporary file. Though you delete
it afterwards, it could have existed already, so you ruin it. If you have
bad luck you won't be permitted to write to it.
I tried to get the output of the executed DOS-command directly into an
InputStream, but didn't succeed in that short time.

Regards,
Hartmut
Technical Details
Message-ID: <3a9f71ea$1_1@dnews>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!bornews.borland.com!dnews!217.3.245.182
References: <3a9ef6c9_1@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,96cf5c3ab3b6aad
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-03-02 02:18:05 PST
From: "Hartmut" <hartmut.kiessling@bnhof.de>
Newsgroups: borland.public.jbuilder.java.language
References: <3a9ef6c9_1@dnews>
Subject: Re: How I read a variable?
Date: Fri, 2 Mar 2001 11:11:58 +0100
Lines: 38
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
NNTP-Posting-Host: 217.3.245.182
Message-ID: <3a9f71ea$1_1@dnews>
X-Trace: 2 Mar 2001 02:11:54 -0800, 217.3.245.182
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!bornews.borland.com!dnews!217.3.245.182