I am trying to call an external program from my python application, but it does not show output and does not work with error 127. Running the command from the command line works fine. (and I'm in the right working directory)
def buildContris (self, startUrl, reportArray): urls = [] for row in reportArray: try: url = subprocess.check_output(["casperjs", "casper.js", startUrl, row[0]], shell=True) print (url) urls.append(url) break except subprocess.CalledProcessError as e: print ("Error: " + str(e.returncode) + " Output:" + e.output.decode()) return urls
Each loop throws the following error: (I also checked e.cmd. It is correct but long, so I omitted it in this example)
Error: 127 Output:
DECISION:
The following code works
app = subprocess.Popen(["./casperjs/bin/casperjs", "casper.js", startUrl, row[0]], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env = {"PATH" : "/usr/local/bin/:/usr/bin"}, universal_newlines=True) app.wait() out, errs = app.communicate()
source share