作者Arton0306 (Ar藤)
看板Python
标题Re: [问题] 从cgi呼叫popen
时间Sat Oct 24 00:40:47 2009
1F:推 dingyuchi:suid 475510/17 20:29
感谢 还在等网管连络
我试着比较ls和自己写一个小py档 用Popen去跑跑看
程式码短短的 像下面这样
#!/usr/local/bin/python
import os
import cgitb
from subprocess import Popen,PIPE
cgitb.enable()
print "Content-type: text/html\n\n"
print "in lstest.py, the uid is %d, the gid is %d" % (os.getuid(),
os.getgid())
com=Popen("writesth.py",stdout=PIPE)
com.wait()
print com.stdout.readlines()
结果显示有错
http://kitty.2y.idv.tw/cgi-bin/cgiwrap/~arton36/Psipred/lstest.py
但如果
com=Popen("writesth.py",stdout=PIPE) 这行
改成
com=Popen("ls", stdout=PIPE)
却又正常抓到ls的结果
请问这是什麽原因呢?
(下面是writesth.py档 没有写档 只有print)
#!/usr/local/bin/python
import os
print "in writesth.py, the uid is %d, the gid is %d" % (os.getuid(),
os.getgid())
※ 引述《Arton0306 (Ar藤)》之铭言:
: 我原本有支程式其中有下面两行
: runAlign=Popen("runpsipred_single "+fileallname, shell=True)
: runAlign.wait()
: runpsipred_single是一个script小程式
: 在freebsd下执行的
: 原本这样写是可以跑的 (会产生一个输出档)
: 但当我把程式改成从网页执行时(用cgiwrap)就不能跑了
: 没产生输出档 但这两行不会有错误通知
: 不知用cgi时 Popen是不是需要改变成什麽样子??
: ====================================================================
: 我在想会不会是shell的关系
: 所以把shell拿掉 不过被挡住了 以下是错误讯息
: Traceback (most recent call last):
: File "test1.py", line 12, in <module>
: runAlign=Popen("runpsipred_single spg", stdout=open("stdout.txt","w"))
: File "/usr/local/lib/python2.5/subprocess.py", line 594, in __init__
: errread, errwrite)
: File "/usr/local/lib/python2.5/subprocess.py", line 1097, in _execute_child
: raise child_exception
: OSError: [Errno 13] Permission denied
: 因为主机不是我管的 不知这样要请网管开启什麽权限呢?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.135.140.149
2F:推 buganini:./runpsipred_single ? 10/24 00:52
3F:→ Arton0306:(._.) ...可以了!!! 感谢呀!!! orz 10/24 01:19