Reputation: 85
Two values 'DEVNULL' and 'PIPE' for stdout and stderr respectively were printed as '-3' and '-1' when I put them into a dic. How to solve this problem except transform them into strings through adding '' symbols because they will be afterwards as arguments incorporated into a subprocess.run function.
from subprocess import DEVNULL, PIPE
F1 = DEVNULL
F2 = PIPE
L1 = {'stdout':F1, 'stderr':F2}
print(L1)
output
{'stdout': -3, 'stderr': -1}
Upvotes: 1
Views: 105
Reputation: 36690
Everything is fine, if you look into subprocess
source you will find that
Constants
---------
DEVNULL: Special value that indicates that os.devnull should be used
PIPE: Special value that indicates a pipe should be created
STDOUT: Special value that indicates that stderr should go to stdout
and
PIPE = -1
STDOUT = -2
DEVNULL = -3
Example:
import subprocess
subprocess.run(['echo', '123'], stdout=subprocess.DEVNULL)
is equivalent to
import subprocess
subprocess.run(['echo', '123'], stdout=-3)
but 1st is less cryptic for someone reading such code
Upvotes: 1