Using sh library with grep command
Peter Otten
__peter__ at web.de
Sat Nov 23 11:29:36 EST 2013
Luca wrote:
> I'm trying to use sh (https://pypi.python.org/pypi/sh) for calling
> system grep command but it's now working as expected.
>
> An example:
>
> import sh
> sh.grep('abc', os.getcwd(), '-r')
>
> But I get the ErrorReturnCode_1: exception, that I learned is the
> normal exit code for grep command when it not found any match.
>
> The error instance object reported that the command run is:
>
> *** ErrorReturnCode_1:
> RAN: '/usr/bin/grep abc /Users/keul/test_sh'
>
> Obviously manually running the command I get some output and exit code 0.
>
> Where I'm wrong?
Did you run grep with or without the -r option?
The code sample and the error message don't match. Maybe you accidentally
left out the -r in your actual code.
More information about the Python-list
mailing list