python - how to capture subprocess error -


in python, run exe made using fortran. use subprocess module. exe accesses , writes several files. if make files readonly, see following trace in python console.

i tried using try, except statements. not capture error. tried using p.stdout.readline(). unsuccessful.

is there systematic way capture sort of errors.

code:

import subprocess p = subprocess.popen('c:\\tgssr\\test.exe' , shell=true, stdout=subprocess.pipe) 

traceback:

forrtl: severe (9): permission access file denied, unit 6, file c:\test\mar22_ssout\rawreadlog.dat  image              pc        routine            line        source              test.exe           0116dc40  unknown               unknown  unknown test.exe           0113d42f  unknown               unknown  unknown test.exe           0112ae97  unknown               unknown  unknown test.exe           0112a1da  unknown               unknown  unknown test.exe           0110d746  unknown               unknown  unknown test.exe           0108b9ac  unknown               unknown  unknown test.exe           01173fe3  unknown               unknown  unknown test.exe           011588f5  unknown               unknown  unknown kernel32.dll       76d33677  unknown               unknown  unknown ntdll.dll          77a39f42  unknown               unknown  unknown ntdll.dll          77a39f15  unknown               unknown  unknown 

run process:

p = subprocess.popen(['c:\\tgssr\\test.exe'], stdout=subprocess.pipe, stderr=subprocess.pipe) # shell = true not needed 

to capture error message:

stdout, stderr = p.communicate() # stdout = normal output # stderr = error output 

check process return code:

if p.returncode != 0:     # handle error 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -