471,319 Members | 1,698 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

run shell commands


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.

Jan 10 '08 #1
1 3875
On Jan 10, 2008 9:24 AM, Riccardo Maria Bianchi
<rb******@physik.uni-freiburg.dewrote:
>
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
Jan 10 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Bigbowser | last post: by
8 posts views Thread by Siemel Naran | last post: by
9 posts views Thread by Amjad | last post: by
16 posts views Thread by John Salerno | last post: by
4 posts views Thread by Anastasios Hatzis | last post: by
5 posts views Thread by inetquestion | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.