2014-05-23 21 views
-1

程序[ex13.py]:如何運行在命令提示符下工作的命令形式的python shell?

import sys 
a = raw_input("Input 3rd variable:") 
print "The script is called:", sys.argv[0] 
print "Your first variable is:", sys.argv[1] 
print "Your second variable is:", sys.argv[2] 
print "Your third variable is:", a 

執行在命令提示: ex13.py 1 3

如何從蟒殼通過給出的argv運行此?

+0

可能重複[調用了一個Python外部命令(http://stackoverflow.com/questions/89228/calling-an-外部命令在-蟒) – luk32

回答

0

如果你想要得到的輸出,你可以這樣做:的

from subprocess import Popen, PIPE 

process = Popen(os.path.dirname("python ex13.py 1 3", shell=True, stdout=PIPE) 

output = process.communicate() 
exit_code = process.wait(); 
相關問題