Python 程序执行任何其他 Python 程序作为参数?

Python program to execute any other Python program as argument?

我正在尝试编写一个 Python 程序来使用 subprocess 执行另一个 Python 程序。这个程序有什么问题,我怎么能把另一个Python程序作为参数呢?

import sys
import subprocess
def dorun(args):
   subprocess.Popen([sys.executable, '%r'] % args)
dorun()

错误是:

najeeb@najeeb:~/Desktop/project$ python new-test.py nmap-test.py 
Traceback (most recent call last):
File "new-test.py", line 9, in <module>
dorun()
TypeError: dorun() takes exactly 1 argument (0 given)

除非您希望能够同时启动多个程序?

import sys
import subprocess
def dorun(args):
   subprocess.Popen([sys.executable, args])
dorun(sys.argv[1])