can't get Runtime.getRuntime().exec to work..
Sohaila Roberts <[email protected]> Fri, 23 Aug 2002 10:37:42 -0230
| Newsgroups | gmane.comp.windows.devel.java.general |
|---|---|
| Message-ID | <[email protected]> |
Hi, I have the following code
String tmp2 = "hmm";
String cmd1 = "html2ps -o "+tmp2+".ps "+tmp2+".html";
System.out.println("going to do "+cmd1);
Process p = Runtime.getRuntime().exec(cmd1);
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
// read the output from the command
String s;
System.out.println("Here is the standard output of the
command:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
//wait for end of process and get exit status
int status ;
status = p.waitFor();
if (status != 0) {
System.out.println("The command returned a status of " +
status);
}
// read any errors from the attempted command
System.out.println("Here is the standard error of the command
(if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
} catch (InterruptedException intexc) {
System.out.println("Interrupted Exception on waitFor: " +
intexc.getMessage());
} catch (IOException e) {
System.out.println("ExecuteCmd.main() : " + e);
} catch (Exception e) {
System.out.println("ExecuteCmd.main() : " + e);
}
and I get the following output
going to do html2ps -o hmm.ps hmm.html
Here is the standard output of the command:
The command returned a status of -1
Here is the standard error of the command (if any):
hmm.ps doesnt get created and i get no errors.. but when i do that command
on the command shell it creates hmm.ps with no problem..
any suggestions why?
thanks
sohaila
You can read messages from the JAVA archive, unsubscribe from JAVA,
or subscribe to other DevelopMentor lists at http://discuss.develop.com.