【发布时间】:2021-08-09 01:44:25
【问题描述】:
我正在尝试使用 subprocess.Popen() 从另一个调用 python 脚本。当我逐行调试程序时它工作得很好,但是当我正常运行程序时,我收到以下错误:
C:\Python38\python.exe: can't open file '"<filepath>\thumbs.py"': [Errno 22] Invalid argument
我不知道问题出在哪里,因为在逐行调试程序时它可以正常工作,因此不确定程序正常运行时究竟发生了什么变化。
我正在尝试将一组参数传递给子进程,然后在子进程中使用 argparse 解析这些参数。
这就是我调用该过程的方式:
cmd = ['python', "\"" + pythonPath + "thumbs.py\"", '-d', "\"" + outputdb + "\"", '-c', "\"" + path + cache + "\""]
subprocess.Popen(cmd).wait()
这是我在子进程中解析参数的方式:
if __name__ == '__main__':
global session
args = None
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--database", action="store", dest="dbname", help="Database to output results to", required=True)
parser.add_argument("-c", "--cache", action="store", dest="cachefile", help="Cache file to scrape.", required=True)
while args is None:
args = parser.parse_args()
谁能发现我错过了什么?
【问题讨论】:
标签: python-3.x subprocess arguments command-line-arguments