2

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.

1
  • 1
    I wonder if MATLAB doesn't initialize your $PATH the same as a shell would. Does running echo $PATH from the terminal produce the same output as running system('echo $PATH') from inside MATLAB? Also of note is that MATLAB appears to be using sh instead of bash, although I don't think that should be a problem in this case. Commented Oct 25, 2014 at 3:49

1 Answer 1

2

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

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

1 Comment

This worked great! I did change from unar to 7za since unar was not in /usr/bin/unar but 7za was.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.