Regarding Python Program with Shell Script

A forum for general discussion of the Python programming language.

Regarding Python Program with Shell Script

Postby janaefx » Tue Apr 08, 2014 4:50 am

Hi,

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 -- "test\r"" (file "/var/www/test.sh" line 5). the same is executing from command line (ie) python /var/www/test.py it executes perfectly

Kindly help me, Thanks in advance

Thanks
Jana
Last edited by Mekire on Tue Apr 08, 2014 5:19 am, edited 1 time in total.
Reason: First post lock.
janaefx
 
Posts: 3
Joined: Tue Apr 08, 2014 4:48 am

Re: Regarding Python Program with Shell Script

Postby janaefx » Tue Apr 08, 2014 8:50 am

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
janaefx
 
Posts: 3
Joined: Tue Apr 08, 2014 4:48 am


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 1 guest