Python TypeError:execv()arg 2只能包含subprocess.Popen上的字符串

Python TypeError:execv()arg 2只能包含subprocess.Popen上的字符串,python,arguments,subprocess,parameter-passing,popen,Python,Arguments,Subprocess,Parameter Passing,Popen,我正在尝试在InputOn中执行外部命令 如果在shell中执行,则命令参数如下所示: osmconvert inputfile -b=bbox -o=outputfile 我试图用fowloows子流程调用它: import subprocess as sb inputfile = '/path/to/inputfile' outputfile = '/path/to/outputfile' bbox = 13.400102,52.570951,13.61957,52.676858

我正在尝试在InputOn中执行外部命令

如果在shell中执行,则命令参数如下所示:

osmconvert inputfile -b=bbox -o=outputfile
我试图用fowloows子流程调用它:

import subprocess as sb

inputfile = '/path/to/inputfile'    
outputfile = '/path/to/outputfile'
bbox = 13.400102,52.570951,13.61957,52.676858

test = sb.Popen(['osmconvert', inputfile, '-b=', bbox, '-o=',outputfile])
这给了我一个错误消息:
TypeError:execv()arg 2必须只包含字符串

有人能暗示一下如何使这项工作成功吗


亲切的问候

您需要将
bbox
转换为所需的字符串表示形式:

test = sb.Popen(['osmconvert', inputfile, '-b', '%d,%d,%d,%d' % tuple(bbox), '-o',outputfile])

您需要将
bbox
转换为所需的字符串表示形式:

test = sb.Popen(['osmconvert', inputfile, '-b', '%d,%d,%d,%d' % tuple(bbox), '-o',outputfile])

您需要将
bbox
转换为所需的字符串表示形式:

test = sb.Popen(['osmconvert', inputfile, '-b', '%d,%d,%d,%d' % tuple(bbox), '-o',outputfile])

您需要将
bbox
转换为所需的字符串表示形式:

test = sb.Popen(['osmconvert', inputfile, '-b', '%d,%d,%d,%d' % tuple(bbox), '-o',outputfile])

您得到的直接错误是由于
bbox
是浮点元组,而不是字符串。如果希望传递
-b
参数,如
-b=13.400102,52.570951,13.61957,52.676858
,可能需要在
bbox
值周围加引号

不过,您可能还有一个问题。注意我在上面的参数字符串中的空格。如果将
bbox
outputfile
作为独立于
'-b='
'-o='
字符串的参数传递,则将得到它们的值与调用的命令中的等号之间的相等空格。这可能有效,也可能无效,这取决于osmconvert处理其命令行参数解析的方式。如果需要将
-b
-o
标志与后面的字符串作为同一参数的一部分,我建议使用
+
将字符串连接在一起:

inputfile = '/path/to/inputfile'    
outputfile = '/path/to/outputfile'
bbox = '13.400102,52.570951,13.61957,52.676858' # add quotes here!

 # concatenate some of the args with +
test = sb.Popen(['osmconvert', inputfile, '-b='+bbox, '-o='+outputfile])

您得到的直接错误是由于
bbox
是浮点元组,而不是字符串。如果希望传递
-b
参数,如
-b=13.400102,52.570951,13.61957,52.676858
,可能需要在
bbox
值周围加引号

不过,您可能还有一个问题。注意我在上面的参数字符串中的空格。如果将
bbox
outputfile
作为独立于
'-b='
'-o='
字符串的参数传递,则将得到它们的值与调用的命令中的等号之间的相等空格。这可能有效,也可能无效,这取决于osmconvert处理其命令行参数解析的方式。如果需要将
-b
-o
标志与后面的字符串作为同一参数的一部分,我建议使用
+
将字符串连接在一起:

inputfile = '/path/to/inputfile'    
outputfile = '/path/to/outputfile'
bbox = '13.400102,52.570951,13.61957,52.676858' # add quotes here!

 # concatenate some of the args with +
test = sb.Popen(['osmconvert', inputfile, '-b='+bbox, '-o='+outputfile])

您得到的直接错误是由于
bbox
是浮点元组,而不是字符串。如果希望传递
-b
参数,如
-b=13.400102,52.570951,13.61957,52.676858
,可能需要在
bbox
值周围加引号

不过,您可能还有一个问题。注意我在上面的参数字符串中的空格。如果将
bbox
outputfile
作为独立于
'-b='
'-o='
字符串的参数传递,则将得到它们的值与调用的命令中的等号之间的相等空格。这可能有效,也可能无效,这取决于osmconvert处理其命令行参数解析的方式。如果需要将
-b
-o
标志与后面的字符串作为同一参数的一部分,我建议使用
+
将字符串连接在一起:

inputfile = '/path/to/inputfile'    
outputfile = '/path/to/outputfile'
bbox = '13.400102,52.570951,13.61957,52.676858' # add quotes here!

 # concatenate some of the args with +
test = sb.Popen(['osmconvert', inputfile, '-b='+bbox, '-o='+outputfile])

您得到的直接错误是由于
bbox
是浮点元组,而不是字符串。如果希望传递
-b
参数,如
-b=13.400102,52.570951,13.61957,52.676858
,可能需要在
bbox
值周围加引号

不过,您可能还有一个问题。注意我在上面的参数字符串中的空格。如果将
bbox
outputfile
作为独立于
'-b='
'-o='
字符串的参数传递,则将得到它们的值与调用的命令中的等号之间的相等空格。这可能有效,也可能无效,这取决于osmconvert处理其命令行参数解析的方式。如果需要将
-b
-o
标志与后面的字符串作为同一参数的一部分,我建议使用
+
将字符串连接在一起:

inputfile = '/path/to/inputfile'    
outputfile = '/path/to/outputfile'
bbox = '13.400102,52.570951,13.61957,52.676858' # add quotes here!

 # concatenate some of the args with +
test = sb.Popen(['osmconvert', inputfile, '-b='+bbox, '-o='+outputfile])

是否尝试str(输入文件)?你也可以对另一个做同样的事情。(输出文件)
arg2的哪一部分必须只包含字符串不清楚?Try-inputfile=str('/path/to/inputfile')outputfile=str('/path/to/outputfile'),相同错误:-(Try-str(inputfile)?您也可以对另一部分执行相同的操作。(输出文件)
arg2的哪一部分必须只包含字符串不清楚?Try-inputfile=str('/path/to/inputfile')outputfile=str('/path/to/outputfile'),相同错误:-(Try str(inputfile)?您也可以对另一个执行相同的操作。(输出文件)
arg2的哪个部分必须只包含字符串
不清楚?Try inputfile=str('/path/to/inputfile')outputfile=str('/path/to/outputfile'),相同错误:-(Try str(inputfile)您也可以对另一个执行相同的操作。(输出文件)
arg2的哪一部分必须只包含字符串不清楚?尝试输入文件=str('/path/to/inputfile')输出文件=str('/path/to/outputfile'),相同的错误:-(另外,
['osmconvert',inputfile'-b',bbox'-o',outputfile也可以工作。
(不,
=
,单独的参数)。@J.F.Sebastian:我不确定这可能行得通。就像我说的,这取决于
osmconvert
如何解析它的参数。我在网上看到的所有示例用法都使用等号和串联值,但工具本身可能比示例显示的更宽容。好的