LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   how to run shell command in java? (https://www.linuxquestions.org/questions/linux-general-1/how-to-run-shell-command-in-java-152547/)

u4u 03-02-2004 07:23 AM

how to run shell command in java?
 
i want to run the shell command in java.Also help me how to run executable files of linux environment in java. As in "c" language we use "system" command to run shell command and executable file. How can i achieve it in Java???

Hangdog42 03-02-2004 07:34 AM

Um, why would you want to since it pretty much defeats the purpose of writing a program in Java? Is there really no Java based way to do what you want?

aizkorri 03-02-2004 09:06 AM

you can use exec command.

Process processName=r1.exec("command");
processName.waitFor();

//sorry I clicked submit by accident

aizkorri 03-02-2004 09:08 AM

I don't remember what you have to import but the command is "exec":

e.g:

Runtime r=Runtime.getRuntime();
Process processName=r.exec("command");
processName.waitFor();//if you want to wait for it


All times are GMT -5. The time now is 07:58 PM.