Re: How to pass shell variable to shell script from python

Discussion in 'Python' started by Gerardo Herzig, Feb 27, 2008.

  1. Rockins Chen wrote:

    >Hi all,
    >
    >I encountered a problem: I have a python script, let's just name it
    >caller.py, It calls a shell script, which is named callee.sh. In callee.sh,
    >it need a shell variable $target, which should be supplied by caller.py(cannot
    >pass by argument). I try to use os.environ to do this, as follows:
    >
    >caller.py
    >------------------
    >#/usr/bin/python
    >
    >import os
    >
    >os.environ["target"] = "localhost.localdomain.org"
    >os.putenv("target", "localhost.localdomain.org")
    >os.system("./callee.sh")
    >-------------------
    >
    >callee.sh
    >-------------------
    >#!/bin/bash
    >
    >echo $target
    >exit 0
    >--------------------
    >
    >But, unluckily, it didn't work. What can I do?
    >
    >TIA,
    >
    >
    >
    >

    Well, if you have to use os.system, that could be
    os.system("export target=localhost.localdomain.org; ./callee.sh")

    Gerardo
    Gerardo Herzig, Feb 27, 2008
    #1
    1. Advertising

  2. Gerardo Herzig <> wrote:
    > Rockins Chen wrote:
    > Well, if you have to use os.system, that could be
    > os.system("export target=localhost.localdomain.org; ./callee.sh")


    Or os.system("env target=localhost.localdomain.org ./callee.sh")

    cu
    Philipp

    --
    Dr. Philipp Pagel
    Lehrstuhl f. Genomorientierte Bioinformatik
    Technische Universit√§t M√ľnchen
    http://mips.gsf.de/staff/pagel
    Philipp Pagel, Feb 27, 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. David Tweet
    Replies:
    0
    Views:
    831
    David Tweet
    Dec 6, 2007
  2. Christian Heimes
    Replies:
    0
    Views:
    590
    Christian Heimes
    Feb 27, 2008
  3. D'Arcy J.M. Cain
    Replies:
    0
    Views:
    850
    D'Arcy J.M. Cain
    Feb 27, 2008
  4. Tricky
    Replies:
    0
    Views:
    563
    Tricky
    Mar 19, 2009
  5. moongeegee

    execute a shell script in a shell script

    moongeegee, Dec 3, 2007, in forum: Perl Misc
    Replies:
    2
    Views:
    241
    Ben Morrow
    Dec 4, 2007
Loading...

Share This Page