我有一个运行一些外部命令并返回其值的脚本。我能够在IDLE中运行脚本就好了,我得到了预期的结果。
当我在Linux shell(Bash)中执行脚本时,它会运行,但没有输出。
退出状态为0。
#!/usr/bin/python
import array,os,subprocess
def vsdIndex(vmVsd):
index = subprocess.call(["/root/indeces.sh", vmVsd], stdout=subprocess.PIPE, shell=TRUE).communicate()[0]
print index
return (firstSerial,lastSerial)
def main():
vsdArray = []
vsdProc = subprocess.Popen(["sc vsd show | tail -n +2 | grep -Ev 'iso|ISO|vfd' | awk '{{print $1}}'"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
while True:
line = vsdProc.stdout.readline()
if line != '':
vsdIndex(line)
print "VSD:", line.rstrip()
print firstSerial
print lastSerial
else:
break
如果我简化它,并在没有该功能的情况下运行,我会有相同的行为:
def main():
vsdArray = []
vsdProc = subprocess.Popen(["sc vsd show | tail -n +2 | grep -Ev 'iso|ISO|vfd' | awk '{{print $1}}'"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
while True:
line = vsdProc.stdout.readline()
if line != '':
print "VSD:", line.rstrip()
else:
break
答案 0 :(得分:0)
您需要调用main()函数。以下是在命令行上运行时自动执行此操作的常用方法:
$response = $client->request('PUT', '/put', ['json' => ['foo' => 'bar']]);