0

I am trying to create a python script to do what I normally do from the cmdline.

From the linux cmdline I issue the following command that works from a parent directory of all my git projects:

> find . -not -name "*_pk.pem" -name "*.pem" -printf "%p\n" -exec winpty openssl x509 -noout -serial -in {} \;

Which interleaves the filename and the cert serial number.

./<path>/<filename_1>.pem
serial=...
./<path>/<filename_2>.pem
serial=...

I try to use the command in a python script but only get the filenames. When printing out stderr I see 'stdout is not a tty', one for each filename.

The command changes slightly within a python script, i.e. esc the print newline but not the trailing semi-colon.

cmd = 'find . -not -name "*_pk.pem" -name "*.pem" -printf "%p\\n" -exec winpty openssl x509 -noout -serial -in {} ;'
result = subprocess.run(cmd, shell=True, capture_output=True)

I have seen the following post; Running shell command and capturing the output

My initial thought is that I need to split the command up and pipe the output of one into the other (i.e. instead of using -exec). However, I have also tried to use pipe on the cmdline but couldn't get it to work.

Can anyone give any working examples as to using one subprocess.run() command, or two with pipe between find and openssl, so as to achive the same output results, i.e. filename then serial number for each file found?

Thank you.

Dodomac
  • 175
  • 15

0 Answers0