Local database reading edition
How to execute NT system command in Java?
Reconstructed from database records, not a captured original forum layout. Dates and display names are retained as recorded; timezone and real-world identity are not inferred. Historical advice, contact details and offers are not current. Original markup is shown as inert text.
Forum index · Java - Tips Of The Day
Opening post
Asha · 2001-04-17 18:00:08
A direct method or class that will allow you to read NT system properties does not exist. However, it can be done as follows: Write a simple batch command file with a dos command to echo the value of the environment variable to a text file, then read the content of the file using methods from File and FileReader classes.
import java.io.*;
public class rtl
{
public static void main(String args[])
{
String command=“c:\\gp.bat”;
Runtime rt = Runtime.getRuntime();
try
{
rt.exec(cmd);
}
catch (IOException e)
{
System.out.println(e);
}
}
}
The file gp.bat
=======
echo %PATH% >> path.txt
Now, using the File and File Reader classes, you can read the file path.txt and determine the NT system properties.
Asha Balasubramanyan
http://www.ammu.org
Source notes
MyCommunity/nandighosha.org.zip!/forum/tools/snitz_forums_2000.mdb
Table: FORUM_TOPICS + FORUM_REPLY · record IDs: 95