Process a perl script within a python script -
i'm trying execute perl script within python script. code below:
command = "/path/to/perl/script/" + "script.pl" input = "< " + "/path/to/file1/" + sys.argv[1] + " >" output = "/path/to/file2/" + sys.argv[1] subprocess.popen(["perl", command, "/path/to/file1/", input, output])
when execute python script, returned:
no info key.
all path leading perl script files correct.
my perl script executed command:
perl script.pl /path/to/file1/ < input > output
any advice on appreciate.
the analog of shell command:
#!/usr/bin/env python subprocess import check_call check_call("perl script.pl /path/to/file1/ < input > output", shell=true)
is:
#!/usr/bin/env python subprocess import check_call open('input', 'rb', 0) input_file, \ open('output', 'wb', 0) output_file: check_call(["perl", "script.pl", "/path/to/file1/"], stdin=input_file, stdout=output_file)
to avoid verbose code, use plumbum
emulate shell pipeline:
#!/usr/bin/env python plumbum.cmd import perl $ pip install plumbum ((perl["script.pl", "/path/to/file1"] < "input") > "output")()
note: code example shell=true
runs shell. 2nd , 3rd examples not use shell.
Comments
Post a Comment