run shell commands

Discussion in 'Python' started by Riccardo Maria Bianchi, Jan 10, 2008.

  1. 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.
    Riccardo Maria Bianchi, Jan 10, 2008
    #1
    1. Advertising

  2. Riccardo Maria Bianchi

    Noah Dain Guest

    On Jan 10, 2008 9:24 AM, Riccardo Maria Bianchi
    <-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
    Noah Dain, Jan 10, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    5,671
    Jonathan Bromley
    Feb 18, 2005
  2. Ben Pfaff

    Re: man pages for C commands (GCC commands)

    Ben Pfaff, Jun 24, 2003, in forum: C Programming
    Replies:
    4
    Views:
    3,953
    Thomas Stegen
    Jun 28, 2003
  3. Tim Stanka
    Replies:
    1
    Views:
    785
    Jeff Epler
    Aug 2, 2004
  4. fileexit
    Replies:
    7
    Views:
    121,923
    Marc 'BlackJack' Rintsch
    Feb 17, 2006
  5. sbrogan
    Replies:
    0
    Views:
    286
    sbrogan
    May 15, 2009
Loading...

Share This Page