Skip to content Skip to sidebar Skip to footer

Shell Script Taking Input From Python Program

I have a shell script which runs a python program which has its own parameters: #!/bin/bash python blah.py var1 var2 ./run key I need to find a way to retrieve the contents of key

Solution 1:

Use this

key=`python blah.py var1 var2`
./run $key

Solution 2:

You can do:

./run $( python blah.py var1 var2 )

The $( ) syntax opens a subshell, and runs the command. The stdout output is then dumped in its place

Solution 3:

One liner demo: (ok, so it's two lines)

$ key=`python -c 'print "hi"'`$ echo$key

Solution 4:

Another alternative to modifying the python script to output the value of the key variable is to modify the python script to call the run program

import subprocess
# ... calculations, andset the "key" variable ...
subprocess.call(["./run", key])

Post a Comment for "Shell Script Taking Input From Python Program"