Skip to content Skip to sidebar Skip to footer

Calling Python From Java (tomcat6) As Sub-process

I am trying to call a python script from a java/tomcat6 webapp. I am currently using the following code: Process p = Runtime.getRuntime().exec('python ')

Solution 1:

The explanation is probably one (or more) of following:

  • The command is failing and writing error messages to its "stderr" fd ... which you are not looking at.

  • The command is failing to launch because the command name is incorrect; e.g. it can't be found on $PATH.

  • The command is trying to read from its stdin fd ... but you haven't provided any input (yet).

  • It could be a problem with command-line splitting; e.g if you are using pathnames with embedded spaces, or other things that would normally be handled by the shell.

Also, since this is python, this could be a problem with python-specific environment variables, the current directory and/or the effective user that is executing the command.


How to proceed:

  1. Determine if the python command is actually starting. For instance. "hack" the "" to write something to a temporary file on startup.

  2. Change to using ProcessBuilder to create the Process object. This will give you more control over the streams and how they are handled.

  3. Find out what is going to the child processes "stderr". (ProcessBuilder allows you to redirect it to "stdout" ...)

Post a Comment for "Calling Python From Java (tomcat6) As Sub-process"