2

I'm trying to run

script.pl < input > output

In python. I tried this:

subprocess.check_call(["script.pl","<","input",">","output"])

Which I guess is not the proper way to do it. Any help would be much appreciated!

1
  • os.system("script.pl < input > output") Commented Jun 6, 2016 at 16:17

2 Answers 2

4

You want to execute the shell command

script.pl < input > output             # 0 args, redirects stdin and stdout

but you are executing the shell command

script.pl "<" input ">" output         # 4 args, and no redirections

If you want to run a shell command, you'll need to run a shell.

subprocess.check_call(["/bin/sh", "-c", "script.pl < input > output"])
  -or-
subprocess.check_call("script.pl < input > output", shell=True)

It would be best if you avoided running a shell at all.

in_fh  = open('input', 'r')
out_fh = open('output', 'w')
subprocess.check_call("script.pl", stdin=in_fh, stdout=out_fh)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I used the in_fh and out_fh approach and it worked perfectly!
0

Keep it simple,

import os
os.system("script.pl < input > output")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.