Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Making a op. sys call

0 views
Skip to first unread message

cre...@my-deja.com

unread,
Dec 13, 2000, 6:49:10 AM12/13/00
to
Hi,

I have the following code throw an IOException, when it tries to execute
a DOS op. sys. command (dir) :

public class MyTest {

public static void main (String[] args) {

Runtime myOpSys = Runtime.getRuntime();

try {

myOpSys.exec("dir");

} catch (Exception e) {

System.err.println("Op. Sys. command failed\n");
e.printStackTrace();
System.err.println("\n");
System.exit(-1);
}

}

}

Print out of exception:

java.io.IOException: CreateProcess: dir error=2
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.<init>(Win32Process.java:64)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:272)
at java.lang.Runtime.exec(Runtime.java:195)
at java.lang.Runtime.exec(Runtime.java:152)
at MyTest.main(MyTest.java:31)


* Any ideas why it's doing this?

Regards,
Cem.


Sent via Deja.com
http://www.deja.com/

cre...@my-deja.com

unread,
Dec 13, 2000, 7:00:54 AM12/13/00
to
In NT, commands such as 'dir,' 'copy,' etc, are part of command.com and
need to be executed indirectly via 'cmd' with the /c switch.

Runtime myOpSys = Runtime.getRuntime();
myOpSys.exec("cmd /c dir");

Rgds,
Cem.

In article <917nnl$bvr$1...@nnrp1.deja.com>,

0 new messages