I am trying to run the following Windows console commands through a Python script:
C:\My\Path\openssl.exe x509 -in C:\My\PEM\mypem.pem -noout -subject > C:\My\Data\data.txt
If put directly into the console, produces the expected 1KB file.
Using subprocess.run()
does not. It produces a file, but a 0KB file as if it is not grabbing the stdout
response.
What I've tried without success:
# produces b''
args = 'C:/My/Path/openssl.exe x509 -in C:/My/PEM/mypem.pem -noout -subject'
data = subprocess.check_output(args)
print (data)
# produces b''
result = subprocess.Popen('C:/My/Path/openssl.exe x509 -in C:/My/PEM/mypem.pem -noout -subject', stdout = subprocess.PIPE)
print (result.stdout)
# produces a 0KB data.txt
# probably also producing a b'' thus the 0KB
subprocess.run('C:/My/Path/openssl.exe x509 -in C:/My/PEM/mypem.pem -noout -subject > C:/My/Data/data.txt')