Execute python from Processing How to run python file from processing. I tried Launch() already. It doesn't do anything. Then i tried exec and process builder. both throw me back with "Unhandled exception type IOException". Any help ?
This works when i wanted to open exe file. But I wanted to open a specific python file.
void setup()
{
exec("C:/Windows/System32/notepad.exe");
}
To simplify,
I have a python file when run will generate a txt file as output. So I want processing to execute the python file and I should see the txt file made
Firstly my apologize for not being more descriptive. I will take a note and be more descriptive from next time. :)
Let me clarify one thing,
When I want to execute a python file, I just double click on it and it runs. I was hoping to the same process but with the support of java. The process to just execute the python file (In more simple words, I want java to do the double click for me)
yes Python is added to path.
Yes. I can
This is my python file
file-output.py
f = open('Z.txt','w')
f.write('hello world')
f.close()
It doesnt need to. I do plan on to. But thats the later stage. And there I plan to send via UDP.
I got the IOException error removed.
The following processing code works but I dont know how to open a python file and execute it.
void setup()
{
Process p =
exec("C:/Users/Ramu/AppData/Local/Programs/Python/Python35/python.exe");
//Process p = exec("C:/Windows/System32/notepad.exe");
try {
int result = p.waitFor();
println("the process returned " + result);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
If I try with
exec("C:/Users/Ramu/AppData/Local/Programs/Python/Python35/test.py");
Answers
And you are trying to do this in JavaScript Mode -- i.e. Processing.js or p5.js...?
The default mode. Not p5.js.
This works when i wanted to open exe file. But I wanted to open a specific python file. void setup() { exec("C:/Windows/System32/notepad.exe"); }
To simplify, I have a python file when run will generate a txt file as output. So I want processing to execute the python file and I should see the txt file made
Just describing the problem (as most folks sadly do in this forum) isn't enough.
It should be accompanied by your runnable attempt as well! [-(
Calling another programming language from another 1 isn't always as easy peasy.
For example, take a look at this all big effort forum question to run Python from Processing: #:-S
https://Forum.Processing.org/two/discussion/23471/combining-two-pieces-of-code/p2#Item_51
Each ".py" file can have any of these demands below so it can successfully run: 8-X
python
inside a terminal?import
any 3rd-party libraries? Are they already system-wide installed?https://GitHub.com/GoToLoop/command/blob/patch-1/src/deadpixel/command/Command.java
Firstly my apologize for not being more descriptive. I will take a note and be more descriptive from next time. :)
Let me clarify one thing, When I want to execute a python file, I just double click on it and it runs. I was hoping to the same process but with the support of java. The process to just execute the python file (In more simple words, I want java to do the double click for me)
This is my python file
file-output.py
f = open('Z.txt','w') f.write('hello world') f.close()
I got the IOException error removed.
The following processing code works but I dont know how to open a python file and execute it.
void setup() { Process p = exec("C:/Users/Ramu/AppData/Local/Programs/Python/Python35/python.exe"); //Process p = exec("C:/Windows/System32/notepad.exe"); try { int result = p.waitFor(); println("the process returned " + result); } catch (InterruptedException e) { e.printStackTrace(); } }
If I try with exec("C:/Users/Ramu/AppData/Local/Programs/Python/Python35/test.py");
it doesnt work