简体   繁体   中英

Can't execute a bash script with python 2.2

SO I've been stuck on this problem for a while now. I have a cgi python script that needs to execute a bash script. I have the following line in my code:

os.system("/complete/path/to/executable/run_summary_page.sh " + labelName)

I've been trying to debug this for hours now and I can't find out why it doesn't execute that correctly. When I run the same exactly line from the command line it works perfectly fine. I have given correct permissions to that bash script and so on, but it still isn't working. Note, I'm forced to use python 2.2 so I'm a little restricted with the number of utilities I have available.

I don't remember all of what is and isn't there back in python 2.2, but you can try a simple alternative for calling that command and seeing what is happening:

import commands
stat, output = commands.getstatusoutput("command")

That isn't the most robust way to run commands, but its an easy way to check whats going on right now. If the stat is != 0 then it failed. You should also be able to see both stdout and stderr in the output

If the stat == 0 and there is nothing interesting in the output , then I suspect your bash script is encountering some circumstance, ending, and not really printing anything useful. Maybe it is expecting certain environment variables, and just ignoring and moving along happily when something isn't right.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM