Reputation: 732
I have some Java code that calls a Python script:
String[] cmd = new String[]{"python", "path/to/script", "arg1", "arg2"}
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(cmd);
As long as the Python script contains no errors it works fine, but as soon as it does it breaks. However, I don't get the error message that I would get if I would run the Python script directly from the command line, so I have to search myself what went wrong where. Not very efficient.
Is it possible to get this message by adding some lines to my Java code?
Upvotes: 1
Views: 1650
Reputation: 168825
See When Runtime.exec()
won't for many good tips on creating and handling a process correctly. Then ignore it refers to exec
and use a ProcessBuilder
to create the process. Also break a String arg
into String[] args
to account for things like paths containing space characters.
Now to the specifics of the problem at hand, it sounds like it is the output from the error stream that is missing. As you noted, calling proc.getErrorStream()
and processing that output should fit the requirement.
Upvotes: 1