Codessentials

  • Increase font size
  • Default font size
  • Decrease font size
Home Coding tips Java Run a shell command

Run a shell command

 If you want to run an external program from java, you cando this as follows:

Process lProcess = Runtime.getRuntime().exec(aCommand + " " + aArguments, null, aWorkingFolder); 

Optionally you can wait for the process to terminate before continuing with your java application. If you want this you add the next statement:

int exitVal = lProcess.waitFor(); 

exitVal will contain 0 on success and another value if the process did not terminate properly.

 

Bookmark

AddThis Social Bookmark Button

Related Articles


Newsflash

Now we have got some coding tips for the developers amongst you!