[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

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

Gerardo Herzig -Departamento de Proyectos Especiales e Internet- Facultad de Medicina

2/27/2008 11:17:00 AM

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
1 Answer

Philipp Pagel

2/27/2008 12:20:00 PM

0

Gerardo Herzig <gherzig@fmed.uba.ar> 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/s...