How to run a python script with an open terminal window on a mac?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Dominik Mattioli
am 8 Apr. 2020
Beantwortet: colordepth
am 10 Mär. 2025
I'm using a socket connection which requires the python script to continuously run. I have this figured out on Windows, where
!python main.py &
launches the python script that initialized the socket with MATLAB and listens for transmissions. I'm really struggling with this on mac, because the same call does not open a terminal (or seem to do anything).
Suggestions?
0 Kommentare
Akzeptierte Antwort
colordepth
am 10 Mär. 2025
On a Windows-based system, doing a
!<shell-command> &
will launch a terminal window to execute the shell command, which is what you are observing. However, on a Unix-based system, doing so will immediately return control to the MATLAB command window and execute "<shell-command>" in the background. You can rest assured that your python script has launched and is running as a background process until either your MATLAB session exits or your python script finishes execution. Here's an old related discussion: https://www.mathworks.com/matlabcentral/answers/85938-how-to-open-new-terminal-visible-from-matlab-linux-mac.
Some limitations with this approach is that one is unable to see the output of the python script and one cannot terminate the exact python process as the Process ID (PID) is not known.
It may be beneficial for you to utilize MATLAB's External Interface for Python and run your script in "Out of Process" execution mode as documented here: https://www.mathworks.com/help/matlab/matlab_external/out-of-process-execution-of-python-functionality.html. This gives the ability to terminate the python process manually using the "terminate" command: https://www.mathworks.com/help/matlab/ref/pythonenvironment.terminate.html.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Call Python from MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!