3

On a unix command line I can do:

paste <(echo A) <(echo B)

However, when I try to do this:

import subprocess
subprocess.call('paste <(echo A) <(echo B)', shell = True)

I get this error:

/bin/sh: -c: line 0: syntax error near unexpected token `('
/bin/sh: -c: line 0: `paste <(echo A) <(echo B)'

Is it not possible to do shell input redirection with the subprocess module?

4
  • 5
    That's probably running /bin/sh as your shell which doesn't do that. You need to try to force it to use /bin/bash. Commented Sep 18, 2014 at 11:23
  • 1
    Thanks Etan! I added executable='/bin/bash' and it worked! Will you leave an answer? Commented Sep 18, 2014 at 11:24
  • have you given the os.system('paste <(echo A) <(echo B)') a try..? Commented Sep 18, 2014 at 13:04
  • Olu, that one fails as well. The subprocess docs reads: "This module intends to replace several older modules and functions: os.system" Commented Sep 18, 2014 at 14:17

1 Answer 1

1

Many things by default use /bin/sh as the shell of choice. /bin/sh is often not bash.

The /bin/sh on your system most likely does not support process substitution.

Convince subprocess.call to use /bin/bash as the shell instead and it should work.

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

2 Comments

Thank you again. This did the trick: subprocess.call('paste <(echo A) <(echo B)', shell = True, executable='/bin/bash')
@tommy.carstensen: even /bin/bash if called using name /bin/sh may use different compatibility mode i.e., no process substitutions.

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.