Monday, 15 March 2010

linux - How to return a value from a shell script in a python script -


I have a dragon script that requires a value from a shell script.

(A.sh):

  #! / Bin / bash return_value () {value = $ (/ / some UNIX commands) "$ value"} return = return_value   

The following is the Python script:

  Reply to Subprocess Import = Subprances Cole ([AK / A.SÃÆ'à ¢ â,¬Å¡Ãƒâ € šÃ, · ??) Print ("Answer is% s% Answer")   

But its work Do not have to. Error "import error: no module subprocess" I think my verison (Python 2.3.4) is very old. Is there any substitute for subprocess in this case ?? check_output :

  import reply to subprocess = subprocess. Checkoutout (['./.sh']) Print ("Answer is {}". Format (Answer))   

Support on subprocess.check_output

  & gt; & Gt; & Gt; Print subprocessation. Run the command with check-output .__ doc__ arguments and return its output as a byte string.   

Demo:

  & gt; & Gt; & Gt; Import sub process & gt; & Gt; & Gt; Answer = subprocess.check_output (['. /.sh']) & gt; & Gt; & Gt; 'Hello World!' Reply to! \ N '& gt; & Gt; & Gt; Print ("Answer is {}". Format (Answer)) Answer Hello World!   

a.sh :

  #! / Bin / bash STR = "Hello World!" ATO $ STR    

No comments:

Post a Comment