[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

run shell commands

Riccardo Maria Bianchi

1/10/2008 2:25:00 PM


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.

1 Answer

Noah Dain

1/10/2008 5:32:00 PM

0

On Jan 10, 2008 9:24 AM, Riccardo Maria Bianchi
<rbianchi@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/p...
>

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