在 Python 中使用 subprocess.call 执行文件时如何解析参数?
How are arguments resolved when executing a file using subprocess.call in Python?
我想从 Python 脚本执行一个 .exe 文件,在 Windows,带有一堆参数。这些参数的一部分是输入文件和输出的路径。
我的问题:我可以将路径保存在一个变量中,然后将其用作参数,还是调用仅采用参数的名称而不是其值?
我的想法:
outputPath = C:\...\folder1\folder2
inputpath = D:\...\folder1\folder2
subprocess.call('runnable.exe', outputPath, inputPath)
而不是
subprocess.call('runnable.exe', C:\...\folder1\folder2, D:\...\folder1\folder2)
与 Python 中的所有其他函数和方法一样,调用函数采用变量或文字作为参数。参见 What is the difference between literal and variables in Python? for more details on those. You may also consider reading through the Python tutorial。它可以很好地介绍 Python.
中的编程
你可以这样做
from subprocess import Popen
outputPath ='C:\...\folder1\folder2'
inputpath = 'D:\...\folder1\folder2'
command='ruunable.exe' + outputPath + inputpath
proc=Popen(command)
我想从 Python 脚本执行一个 .exe 文件,在 Windows,带有一堆参数。这些参数的一部分是输入文件和输出的路径。
我的问题:我可以将路径保存在一个变量中,然后将其用作参数,还是调用仅采用参数的名称而不是其值?
我的想法:
outputPath = C:\...\folder1\folder2
inputpath = D:\...\folder1\folder2
subprocess.call('runnable.exe', outputPath, inputPath)
而不是
subprocess.call('runnable.exe', C:\...\folder1\folder2, D:\...\folder1\folder2)
与 Python 中的所有其他函数和方法一样,调用函数采用变量或文字作为参数。参见 What is the difference between literal and variables in Python? for more details on those. You may also consider reading through the Python tutorial。它可以很好地介绍 Python.
中的编程你可以这样做
from subprocess import Popen
outputPath ='C:\...\folder1\folder2'
inputpath = 'D:\...\folder1\folder2'
command='ruunable.exe' + outputPath + inputpath
proc=Popen(command)