execute bash builtins in python
Steve Holden
steve at holdenweb.com
Fri Mar 12 08:15:49 EST 2010
alex goretoy wrote:
> hi,
> i'm trying to write a section of my program that needs to run bash
> builtin alias and declare, i've googled and tried every type of example
> i could find no to avail. this is what I've tried below and it doesn't
> work, is there a way for me to execute a bah builin from python? what i
> need is to take alias output and pipe it to another command with python
> and return the results to a string or list.
>
>>>> p1=Popen(["alias"],stdout=PIPE)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "/usr/lib/python2.6/subprocess.py", line 621, in __init__
> errread, errwrite)
> File "/usr/lib/python2.6/subprocess.py", line 1126, in _execute_child
> raise child_exception
> OSError: [Errno 2] No such file or directory
>
> if i add shell=True i get empty string and no thins error message
>
>>>> p1=Popen(["alias"],stdout=PIPE,shell=True)
>>>> p1
> <subprocess.Popen object at 0xb7589a4c>
>>>> p1.stdout.read()
> ''
>
> thank you,
> -Alex Goretoy
>
For shell=True I believe you should provide the command as a single
string, not a list of arguments.
>>> p1 = Popen("alias", stdout=PIPE, shell=True)
>>>
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS: http://holdenweb.eventbrite.com/
More information about the Python-list
mailing list