I am trying to run a praat file from python itself with subprocess but python(subprocess) can't seem to find the directory. I don't understand why since when I run the command in terminal, it works perfectly fine. Cant anyone guide me to where I am going wrong? This is the subprocess code
import silex
import subprocess as sb
cmd_line = raw_input()
args = shlex.split(cmd_line)
p = sb.Popen(args)
When I run it with the input
Praat /Users/admirmonteiro/tmp/tmp.praat
this is the error that I get :
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/Users/admirmonteiro/anaconda/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/Users/admirmonteiro/anaconda/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
As mentioned, I run the commands and they run fine in the terminal. I have also tried to run subprocess.call but the same error occurs. I have also tried with with shell=True as an argument but that also outputs the same error. Please Help !
1 Answer 1
Type the following in the shell to get the full path of the Praatapplication.
whereis Praat
Then use the full path in you python program.
4 Comments
type Praat (whence, where, which) or command -v Praat might be more useful here, to find the full path to the executable. See What is the unix command to find out what executable file corresponds to a given command? whereis checks the standard binary directories (...) printing out the paths of any it finds, which will locate a program in the user's path. Therefore which is probably a better choice, since the OP said he was able to run it in the command line.type Praat if you run the command interactively in a shell or command -v Praat if it is in a script. It is more likely that type will show the actual executable that will be run than whereis.
which Praatreturn when run from the shell manually?