So I want to get a Perl script to activate from Python and after some time I have gotten to a stage where it executes it, but I get no output, and I don't know what is wrong.
I don't even know if it recognises the script or the input files, because it accepts everything and gives no error message.
script = subprocess.Popen(["perl" , "C:\\Users\\...\\pal2nal.pl" , "C:\\Users\\...\\input_file" , "C:\\Users\\...\\output_file" ], stdout=subprocess.PIPE)
while True:
line = script.stdout.readline()
if line == b'' and script.poll() != None:
break
sys.stdout.write(line.decode('utf-8'))
sys.stdout.flush()
output = script.communicate()[0]
exitCode = script.returncode
This is the script if anyone is interested http://www.bork.embl.de/pal2nal/distribution/pal2nal.v14.tar.gz
This is my first time working with subprocesses and have tried with error checking but was ultimately unsuccessful.
To display the subprocess output line-by-line as soon as it arrives and to capture it in a variable:
#!/usr/bin/env python3
import io
from subprocess import Popen, PIPE
lines = []
with Popen(["perl" , r"C:\Users\...\pal2nal.pl",
r"C:\Users\...\input_file",
r"C:\Users\...\output_file"],
stdout=PIPE, bufsize=1) as p:
for line in io.TextIOWrapper(p.stdout, encoding='utf-8'):
print(line, end='')
lines.append(line)
output = ''.join(lines)
print(len(lines), p.returncode)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.