简体   繁体   中英

Get Exceptions from popen in python

I executed this code in python: (test.py)

from subprocess import Popen
p = Popen("file.bat").wait()

Here is file.bat:

@echo off
start c:\python27\python.exe C:\Test\p1.py %*
start c:\python27\python.exe C:\Test\p2.py %*
pause

Here is p1.py:

This line is error
print "Hello word"

p2.py is not interesting

I want to know the exception(not only compiling error) in p1.py by running test.py? How can I do this?

Thanks!

Here's how I got it working: test.py

from subprocess import Popen
p = Popen(["./file.sh"]).wait()

Make sure to add the [] around file, as well as the ./ . You can also add arguments, like so: ["./file.sh", "someArg"] Note that I am not on Windows, but this fixed it on Ubuntu. Please comment if you are still having issues

EDIT: I think the real solution is: Using subprocess to run Python script on Windows

This way you can run a python script from python, while still using Popen

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM