We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have a simple command I need to run in my mac terminal:
python /Users/J/Desktop/sketch1/data/scripts/segmenting.py
How can I make processing run this command in the terminal instead of me opening the terminal and tying it in?
I thought about saving the terminal output as a file to call it, but not sure about that.
Thanks for the help
Answers
From the launch reference:
exec()
In the Processing API:Edit: removed voice argument from example above as per https://github.com/processing/processing/pull/5282
So for example in my mac terminal I am writing:
python /Users/J/Desktop/sketch1/data/scripts/segmentation_pipeline.py /Users/J/Desktop/sketch1/data/images/test2.jpg
How do I call terminal to write this from processing then?
It should be like in the example:
Depending on how your path is set up you may need to provide the full path to the python executable (check with
which python
) e.g./usr/bin/python
I get this little grey box that pops up, but I dont think the script worked because the script creates a folder and its nowhere to be found..
/Users/J/anaconda3/bin/python3.6
is where my python is at...how do I include the full path ?
/Users/J/anaconda3/bin/python3.6/python
(or python3, or whatever the binary is called)Yeah im getting nothing at all. Is there a way of opening terminal instead of python? If I can open terminal and automatically put this line in, it runs perfectly in my terminal.
Try using the "if you want to wait until it is completed" code example from the
exec()
JavaDoc so that you can read the return text in the console.Here is a combined example that attempts both test2 output ( no console capture) and test3 output (console capture):
I have not included full paths for any of the exec arguments.
You also might want to consider simplifying things by making the script file and output local to your sketch, at least for the purposes of testing.
This works....but can I not just say in processing "open this .txt file in terminal.app?" How do you open external applications and processes?
If you want to open
TextEdit.app,
use Processing'slaunch()
.If you want to run a shell command (like in Terminal.app), use
exec()
.I don't believe you can "open this .txt file in terminal.app" ... because Terminal.app doesn't work that way -- it isn't a document editor. For example, it doesn't have an open command in its menu, and dragging a text file onto it won't do what you think.
Ok, I have a different idea...I looked up:https://macosx.com/threads/text-file-executable.312801/
and made it an executable file, so now its just one file called "image" which contains the same: /Users/J/Desktop/sketch1/data/scripts/segmentation_pipeline.py /Users/J/Desktop/sketch1/data/images/test2.jpg
how can I call this file?
launch("/Users/J/Desktop/image");
Works! Success!