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

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

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. Steve
    Replies:
    1
    Views:
    384
    Rene Pijlman
    Jan 3, 2004
  2. spec
    Replies:
    7
    Views:
    77,316
    Cameron Laird
    Jul 18, 2006
  3. Gros Bedo
    Replies:
    2
    Views:
    1,583
    Piet van Oostrum
    Jul 10, 2008
  4. Gros Bedo
    Replies:
    1
    Views:
    800
    Piet van Oostrum
    Jul 10, 2008
  5. Samuel A. Falvo II
    Replies:
    0
    Views:
    645
    Samuel A. Falvo II
    Oct 8, 2008
  6. Tricky
    Replies:
    0
    Views:
    782
    Tricky
    Mar 19, 2009
  7. sitnam81
    Replies:
    11
    Views:
    621
    Tad McClellan
    Apr 29, 2005
  8. moongeegee

    execute a shell script in a shell script

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