0_o
0_o

Reputation: 333

Running python script from matlab not working, but runs fine from terminal

I have a python script say script.py that I can call from the terminal no problem, in the middle of the script it unarchives a file using os.system('unar file'). However, when trying to run this script from matlab using system('python script.py') it runs, but then when it gets to the unar line, it states "sh:unar: command not found".

How is this possible? Isn't the matlab system command supposed to be the same as the terminal? Any help is appreciated.

Upvotes: 2

Views: 559

Answers (1)

VooDooNOFX
VooDooNOFX

Reputation: 4762

In your terminal, your python script get to benefit from your PATH environment, so it knows where the /usr/bin/unar application is located. Within Matlab, it doesn't. You need to give your os.system call the full path to both your application, and your file.

Also, os.system is pretty awful. Use subprocess.Popen instead, which allows redirection of sys.stdin and sys.stdout.

Here's a gist example using subprocess: https://gist.github.com/voodoonofx/8e5bcae8e0b0c5741148

Upvotes: 2

Related Questions