Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在命令提示符形式的pythonshell中运行命令?_Python_Shell - Fatal编程技术网

如何在命令提示符形式的pythonshell中运行命令?

如何在命令提示符形式的pythonshell中运行命令?,python,shell,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

程序[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运行此命令?

如果要获得输出,可以执行以下操作:

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();
可能重复的