run shell commands

Noah Dain noahdain at gmail.com
Thu Jan 10 12:31:53 EST 2008


On Jan 10, 2008 9:24 AM, Riccardo Maria Bianchi
<rbianchi at physik.uni-freiburg.de> wrote:
>
> Hello! :)
>
> I'm trying to run shell commands both with os.system() and
> subprocess.Popen() class.
>
> But I can't run aliases or function defined in my .bashrc file, like in
> the login interactive shell.
>
> Can you help me?
> Maybe have I to add some commands to load the .bashrc?
>
> Thanks a lot! :)
>
>     Ric.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

you'd need to run an instance of the shell from python and probably as
a login shell so that it pulls in .bashrc.

so you'd need a command line like: /bin/bash -l -c "shell commands to
run go here"

if you want to feed more commands to bash, then use -s.  It will read
commands from standard input, which you would feed it from python,
probably by writing to a Popen pipe.

A lot of people also use the pexpect python library to "drive" other
programs, especially if you need python to act differently depending
upon the output of the called programs.

Either way, this list's archives do have some good examples as to the
uses and limitations of both subprocess and pexpect.

-- 
Noah Dain
"The beatings will continue, until morale improves" - the Management



More information about the Python-list mailing list