Question

I'm trying to run a Python program from within Java using the following statement

Process p = Runtime.getRuntime().exec("python " + file);

Where file is a string "c:\user\test.py"

It throws me an exception

Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified

I made sure my system variable has an entry pointing to my python home directory.

please help

Was it helpful?

Solution

Just posting this for future reference (And so the question can be marked solved), the problem was for some reason, Java didn't like that you were trying to run python by calling it python, and it wanted you to do

Process p = Runtime.getRuntime().exec("Path\\To\\Python.exe " + file);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top