execute bash builtins in python

Steve Holden steve at holdenweb.com
Sat Mar 13 14:08:24 CET 2010


alex goretoy wrote:
> I found this to be even better; maybe someone will find this useful, who
> knows.
> just export PS1, duh
> Popen(["bash -c 'export PS1='python'; source
> $HOME/.bashrc;alias'"],shell=True,stdout=PIPE).stdout.read()
> 
Try using an interactive shell:

>>> from subprocess import *
>>> p1 = Popen("bash -i -c alias", stdout=PIPE, shell=True)
>>> p1.stdout.read()
"alias ls='ls --color=auto'\n"
>>>

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