return a value to shell script

News123 news123 at
Fri Nov 14 22:01:42 CET 2008

I don't know what exactly your python script is doing and what kind of
return value you have,

Let's assume your python application prints nothing to stdout, then
python could print out the return value and you could get it with the
back ticks (reverse single quote)
(at least for sh bash csh tcsh and probably also for ksh and some others)

>>>>>>>>>> beginning of python script
import sys
b = int(sys.argv[1])
###your python script can still print to stderr if it likes to
print >> sys.stderr, "I am no converting"
result = a[b]
print result
>>>>>>> end of python script

>>>>>beginning of shell script

text=`python $num`
echo "$num as text is $text"
>>>>> end of shell script



devi thapa wrote:
> Hi,
> I am executing a python script in a shell script.  The python script
> actually returns a value.
> So, can I get the return value in a shell script? If yes, then help me out.
> Regards,
> Devi

More information about the Python-list mailing list