run shell commands

  • Thread starter Riccardo Maria Bianchi
  • Start date
R

Riccardo Maria Bianchi

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.
 
N

Noah Dain

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.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top