This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: subprocess.returncode not set depending on arguments to subprocess.run
Type: Stage: resolved
Components: Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: nthompson, r.david.murray
Priority: normal Keywords:

Created on 2017-10-27 00:20 by nthompson, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg305094 - (view) Author: Nick (nthompson) Date: 2017-10-27 00:20
If subprocess.run is called with a single string, say:

completed_ps = subprocess.run('mpirun -np 4 myexe.x moreargs', shell=True)

and 'myexe.x moreargs' fails with a returncode of 1, then 'completed_ps.returncode' is None. However, if we split the args with shlex, we obtain the desired result, which is a returncode of 1:

import shlex
args = shlex.split('mpirun -np 4 myexe.x moreargs')
completed_ps = subprocess.run(args)
# now completed_ps.returncode = 1 if myexe.x moreargs fails.

Reproduced on Mac, Ubuntu 17.04, Python 3.6.1 and Python 3.6.3.
msg305096 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-10-27 00:50
If you run

  mpirun -np 4 myexe.x moreargs; echo $?

in /bin/sh, what do you see?  You also might try to make sure it is the same mpirun and the same myexe.x that is being called in both cases (it is the mpirun return code you are seeing).
msg305097 - (view) Author: Nick (nthompson) Date: 2017-10-27 03:28
I have verified that

$ mpirun -np 4 myexe.x moreargs; echo $?
1
History
Date User Action Args
2022-04-11 14:58:53adminsetgithub: 76062
2017-10-27 21:24:41nthompsonsetstatus: open -> closed
resolution: not a bug
stage: resolved
2017-10-27 03:28:32nthompsonsetmessages: + msg305097
2017-10-27 00:50:46r.david.murraysetnosy: + r.david.murray
messages: + msg305096
2017-10-27 00:20:33nthompsoncreate