Ying Liu
Posts: 2
Nickname: yl
Registered: Jun, 2002
|
|
Runtime.getRuntime().exec()
|
Posted: Jul 1, 2002 5:51 AM
|
|
Advertisement
|
Hi,
I have a question abotu runtime.exec().
I wrote a .BAT file (1.bat), whihc is to list all the file in C:\ (dir c:\). I can run it using DOS.
Then I try to run it using Runtime.getRuntime().exec(1.bat) in Windows 2000. But it does work. Can anyone tell me what is wrong?
it does not show anything. The exitVal = 1.
public void test() {
String[] cmdLine = {"cmd.exe", "/c", "1.bat"};
String line = "";
try
{
java.lang.Process djProc = Runtime.getRuntime().exec(cmdLine);
System.out.println("1");
djProc.waitFor();
System.out.println("HERE");
BufferedReader input = new BufferedReader(new InputStreamReader(djProc.getInputStream()));
System.out.println("LINE = " +line);
while ((line = input.readLine()) != null) {
System.out.println(line);
}
System.out.println("in Here");
System.out.println("exitval = " + djProc.exitValue());
}
catch (Exception e)
{
System.out.println(e.toString());
} }
|
|