some commands working properly(notepad ,control(control panel))...
but how to execute commands "dir" like that
my code is ...
public class test1{
public static void main(String args[])throws Exception{
Runtime r= Runtime.getRuntime();
Process p1=r.exec("notepad");//working fine
Process p2=r.exec("control");//working fine
Process p3=r.exec("test1.java");//cannot run
Process p4=r.exec("dir");// cannot run
}
}
o/p:
F:\studies\java\test>java test1
Exception in thread "main" java.io.IOException: Cannot run program "test1.java":
CreateProcess error=193, %1 is not a valid Win32 application
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at test1.main(test1.java:18)
Caused by: java.io.IOException: CreateProcess error=193, %1 is not a valid Win32
application
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 5 more