I am calling a perl script on an external txt files from python, and printing the output to an outfile. But instead I want to pipe the output to unix's sort. Right now I am not piping, but are writing the output from the perl program first, then doing by combining my code under, and this stackoverflow answer.
import subprocess
import sys
import os
for file in os.listdir("."):
with open(file + ".out", 'w') as outfile:
p = subprocess.Popen(["perl", "pydyn.pl", file], stdout=outfile)
p.wait()
p = subprocess.Popen("perl pydyn.pl %s | sort" % file, stdout=outfile,shell=True)
but for this you're gonna have to make itshell=True
which is not a good practice – Ailee