Problem working with subprocess.check_call

Pete Dowdell contact at stridebird.com
Thu Oct 29 06:06:24 EDT 2015


On 29/10/15 16:52, David Aldrich wrote:
>
> 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)
>

You could use a shell pipe in your command - and use str.format() too 
for better readability, perhaps:

 > cmd = 'diff  {} {} | head -20'.format( file1, file2 )
 > subprocess.check_call(cmd, shell=True)

Although this approach would not be recommended if file1 or file2 are 
not sanitised

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


More information about the Python-list mailing list