• Advertisement
Sign in to follow this  

[java] Running an exe in Java

This topic is 4705 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need to run an exe from java. I no in vb u just use Shell but I have no clue how to do it in Java. Jake

Share this post


Link to post
Share on other sites
Advertisement
shell cmd ?

see java documentation of Runtime.exec(String cmd[,String []envp])

in this example cmd is bat file name so I just pushing my commands to bat and then execute alls in one instead of this type of collection object You can pass to this function single DOS or WINSHELL or script.

void runmyshell(String cmd)
{
String s = null;
try
{
Process p=Runtime.getRuntime().exec(cmd);
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
// read the output from the command
while ((s = stdInput.readLine()) != null)System.out.println(s);
// read any errors from the attempted command
while ((s = stdError.readLine()) != null)System.out.println(s);
}
}catch(IOException e)
{
System.out.println(e);
}
}
}




[Edited by - HellCreator on June 1, 2005 9:55:47 AM]

Share this post


Link to post
Share on other sites
You can try looking at this too:

http://www-ppg.dcs.st-and.ac.uk/Java/DynamicCompilation/


It invokes the Java compiler from the command line, and test for shell, and uses some of the system properties. It's good looking code for the most part (except for the >80 char per line thing). So basically easy to understand.

L-

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement