May-30-2018, 09:31 AM
I think the problem is that 'cpt.py' is not an executable, so Popen fails in the execution.
As you have also redirected the stderr to a pipe you cannot see the error message that shall looks like "cpt.py: Not an executable"
In linux/mac the trick is as easy as adding the next header to cpt.py:
Other option is to run the script calling the python executable with something like:
As you have also redirected the stderr to a pipe you cannot see the error message that shall looks like "cpt.py: Not an executable"
In linux/mac the trick is as easy as adding the next header to cpt.py:
#!/usr/bin/env python3 # The previous line must be the 1st line, no spaces before the #.And set the executable flag from the command line:
Output:$> chmod +x cpt.py
For windows, refer to the official faq.Other option is to run the script calling the python executable with something like:
cmd = "cpt.py" with subprocess.Popen(['python', cmd], stdout=subprocess.PIPE,stdin=subprocess.PIPE,stderr=subprocess.PIPE) as p: txt = p.stdout.readline() # read the print i (line 2) p.stdin.writelines(txt) # write it (line3) a = p.stdout.readline() # read the print a (line 3) b = p.stdout.readline(ans) # read (line 2) second time p.stdin.writelines(b) # write it(line 3) second time c = p.stdout.readline() # read (ligne 3) second time