Running DOS commands in Java

Hi all..I need help in running the DOS commands using my java program..I am new to this area of Java.. please let me know the methods..Thanks in advance..
[189 byte] By [Ragav_Msca] at [2007-11-27 4:05:02]
# 1
You can use java.lang.Runtime Class and Process Class in Java standard library to use the same!Java.lang.Runtime object= Runtime.getRuntime();Process p=null;p=object.exec("Dos Command");Read more about it in Java Docs.
Nikksa at 2007-7-12 9:09:58 > top of Java-index,Java Essentials,New To Java...
# 2

Hi i used the logic of yours... but i am getting the error

C:\Socket>java Serial dir

Exception in thread "main" java.io.IOException: CreateProcess: dir error=2

at java.lang.Win32Process.create(Native Method)

at java.lang.Win32Process.<init>(Unknown Source)

at java.lang.Runtime.execInternal(Native Method)

at java.lang.Runtime.exec(Unknown Source)

at java.lang.Runtime.exec(Unknown Source)

at java.lang.Runtime.exec(Unknown Source)

at java.lang.Runtime.exec(Unknown Source)

at Serial.main(Serial.java:9)

My program...

import java.lang.*;

import java.io.*;

public class Serial{

public static void main(String args[])throws IOException{

Runtime object= Runtime.getRuntime();

Process p=null;

p=object.exec(args[0]);

}

}

Ragav_Msca at 2007-7-12 9:09:58 > top of Java-index,Java Essentials,New To Java...
# 3
since Java doesn't run on DOS, you're not going to be able to run DOS commands from Java.You might be able to get a network connection to a program running on a DOS machine which executes the commands and sends the results back, but that's something else entirely.
jwentinga at 2007-7-12 9:09:58 > top of Java-index,Java Essentials,New To Java...
# 4
Thanks ... i am not fully got ur points but i have to investigate on this.. thanks for your immediate help..I need help on setting up the Serial port settings using java programs..please give some clue..
Ragav_Msca at 2007-7-12 9:09:58 > top of Java-index,Java Essentials,New To Java...