Problem working with subprocess.check_call

David Aldrich David.Aldrich at EMEA.NEC.COM
Thu Oct 29 05:52:56 EDT 2015


Hi

I am working on Linux with Python 3.4.

I want to do a bash diff on two text files and show just the first 20 lines of diff's output.  So I tried:

>>> cmd = 'head -20 <(diff ' + file1 + ' ' + file2 + ')'
>>> subprocess.check_call(cmd, shell=True)

The command contained in cmd works ok from the bash prompt but not from Python code.  In Python I get:

/bin/sh: -c: line 0: syntax error near unexpected token `('

I think the problem is that check_call is not using the bash shell.  So I also tried:

>>> subprocess.check_call("bash", "-O", "extglob", "-c", cmd)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/subprocess.py", line 556, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/local/lib/python3.4/subprocess.py", line 537, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/local/lib/python3.4/subprocess.py", line 767, in __init__
    raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer

Can anyone help me with this please?

Best regards

David

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20151029/3bc8370e/attachment.html>


More information about the Python-list mailing list