Regarding Python Program with Shell Script

Hi All,

I have written a shell script which is using the expect method, it is working fine in terminal window, and then I have executed via python script its also working fine in command prompt functioning properly, I used subprocess.Popen method to execute the shell script file, its working fine in terminal window, when I try to execute via web browser it says that error "send: spawn id exp3 not open while executing "send -- "pwd\r"" (file "/var/www/Site/test.sh" line 5). the same is executing from command line (ie) python /var/www/Site/test.py it executes perfectly

Below is my shell script and python script

#!/usr/bin/expect -f
#!/bin/bash
spawn command
expect "Password:"
send -- "pwd\r"
send -- "\r"
expect eof

#below is my python script to execute the shell script files

#!/usr/bin/python
import MySQLdb
import subprocess
import pexpect
import cgi
import sys
import os
import urllib
import cgitb
import Cookie

try:

command="/var/www/Site/test.sh"
proc=subprocess.Popen(command,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
(stdout,stderr)=proc.communicate()
if stderr:
print "Content-type:text/html\n\n Fail: "+command+str(stderr)
else:
print "Content-type:text/html\n\n Success"+command
except:
e=sys.exc_info()[1] 
print "Content-type:text/html\n\n fails"+str(e)
 

Thanks in advance

Thanks
Jana