1

I am running an external program using pipes in python and it works fine. However I would like to pass two arguments to this external program.

Could anyone help me with that?

Thanks!

1
  • 2
    Show us the code you're using. Commented Aug 9, 2011 at 15:49

1 Answer 1

4
from subprocess import Popen, PIPE

p = Popen(['external-program', 'arg1', 'arg2'], 
                stdin=PIPE, stdout=PIPE, stderr=PIPE)

if you mean piping the out into or out of the Python script, or

from subprocess import Popen, PIPE

p = Popen('external-program arg1 arg2 | external2'], shell=True)

if you mean piping output between external programs.

See the subprocess docs. Post your code if you want a different type of solution.

Sign up to request clarification or add additional context in comments.

10 Comments

If he's actually using pipes between external programs you do. It's not clear from the question whether the pipes were between Python and the external program or what.
The only time you need shell=True is when you are on windows and you need to call commands that are cooked into cmd.exe
so you're saying 'cat file1 | grep "glob"' would work without shell=True? What would interpret the pipe?
Why would you pipe inside the subprocess and rather not redirect the output in python.
I'm not saying it's advisable, I'm saying it might be what he's doing now. I've edited my answer to split it up into two parts.
|

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.