如何从python shell运行命令提示符下的命令?

时间:2014-05-23 11:18:54

标签: python shell

计划[ex13.py]:

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来从python shell运行它?

1 个答案:

答案 0 :(得分: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();