0

I'm on a Windows machine and using Eclipse. My java code is invoking a python script by using :

Process p = Runtime.getRuntime().exec("cmd /c e:\\dev\\CodeBase\\WebService\\src\\com\\rest\\service\\PythonScript.py");

On running the code it opens the prompt for choosing a program to run the script with. What can I do to make it run implicitly?

1
  • Check your PATH for env. variables. If you have Python in the path already, then prefix python to the path of your script; not cmd /c. It should like like python my_scriptpath.py in your command. Commented Nov 8, 2014 at 11:42

2 Answers 2

1

Try running Python interpreter instead:

Process p = Runtime.getRuntime().exec("[PATH TO YOUR PYTHON DIR]\\python.exe e:\\dev\\CodeBase\\WebService\\src\\com\\rest\\service\\PythonScript.py");

Usually [PATH TO YOUR PYTHON DIR] is something like C:\\Python27\\ or C:\\Python34 depending on your Python version.

If you have Python directory added to your system PATH variable sole .exec("python ...") will suffice.

Sign up to request clarification or add additional context in comments.

9 Comments

That prompt doesn't come up now. But my output is blank. My .py file is simple - def main(): return "Hello World". Is this right?
@Natasha No, this script won't do nothing. But it shouldn't be any problem for you to fix it: try searching "hello world in python" via google and you'll find lots of examples. You might want to add input() (or raw_input() for Python2) call at the end, so the window won't disappear immediately.
I didnt get that part. what input?
@Natasha So it will wait for the user to press the "enter" key, before the window disappears. It's not essential, if you see the console view in Eclipse after the program finishes - if yes, disregard that part. Otherwise, the script will run very fast, and the console will disappear before you will be able to see anything.
I'm using the Eclipse console.
|
1

You will need to convert the .py file to .exe use Py2Exe. You can download it and follow the instructions to convert it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.