2

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 !

6
  • What does which Praat return when run from the shell manually? Commented Feb 24, 2016 at 22:55
  • If I type it in by itself, it opens the app. If I open it with the file as I mentioned, it runs the file which returns another file. Which if I do that in terminal it works. Commented Feb 24, 2016 at 22:57
  • Also when I run subprocess.call([Praat"]) , I got the error : call(["Praat"],shell=True) /bin/sh: Praat: command not found 127 this makes no sense because when I run Praat in terminal, it works. I am confused . Commented Feb 24, 2016 at 23:01
  • Try with the full path to Praat Commented Feb 24, 2016 at 23:04
  • Also your script don't make any sense, you read a command from the command line and run it? Why not just run the command to begin with instead Commented Feb 24, 2016 at 23:09

1 Answer 1

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.

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

4 Comments

note: 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?
According to man pages, 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.
Read the links I've provided (really, the answers there are very thorough). Use 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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.