4
我使用子進程從下面的一個調用python腳本。在命令行中的用戶選擇使用的raw_inputPython調用子進程的raw_input
import optparse
import subprocess
import readline
import os
def main():
options = {'0': './option_0.py',
'1': './option_1.py',
'2': './option_2.py',
'3': './option_3.py'}
input = -1
while True:
if input in options:
file = options[input]
subprocess.Popen(file)
else:
print "Welcome"
print "0. option_0"
print "1. option_1"
print "2. option_2"
print "3. option_3"
input = raw_input("Please make a selection: ")
if __name__ == '__main__':
main()
但是在被稱爲子(說option_1.py叫)我的raw_input使用再次接受來自用戶提示有問題要打開的文件。我知道的.PIPE的論點,並試圖
subprocess.Popen(file, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
但是再次沒有運氣。
我個人會做這個作爲非交互成爲可能。 – 2010-01-17 13:47:42