我正在尝试使用Subprocess从 Python 调用 shell 脚本。当我从终端调用我的脚本时,我使用:
// Passing string, int, string, string
sh script.sh "firstArgument" 4040 "thirdArgument" "fourthArgument"
所以,我认为这是在 Python 中使用以下方法的正确方法subprocess
:
args = ['sh script.sh', "firstArgument", 3030, "thirdArgument", "fourthArgument"]
val = subprocess.check_call(args, shell=True)
但是当我运行这段代码时,我收到以下错误:
Traceback (most recent call last):
File "main_console.py", line 129, in <module>
app.main()
File "main_console.py", line 34, in main
val = subprocess.check_call(args, shell=True)
File "/usr/lib/python2.7/subprocess.py", line 506, in check_call
retcode = call(*popenargs, **kwargs)
File "/usr/lib/python2.7/subprocess.py", line 493, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
TypeError: execv() arg 2 must contain only strings
我该怎么做才能将这些参数发送到我的脚本而不会收到错误?
编辑:
问题不在于论点本身。我可以向我的脚本发送一个整数。现在的问题是:当我从终端运行我的 sh 时,如下所示:
sh script.sh "blabla" "400" "blabla" "blabla"
这行得通。但是当我用这段代码运行我的python文件时:
args = ['sh script.sh', "firstArgument", 3030, "thirdArgument", "fourthArgument"]
val = subprocess.check_call(args, shell=True)
我收到以下错误:
Removing proxy configuration.
(gconftool-2:28078): GConf-WARNING **: Failed to load source "xml:readwrite:/home/root/.gconf": Failed: Could not make directory `/home/root/.gconf': No such file or directory
**
GConf:ERROR:gconftool.c:969:main: assertion failed: (err == NULL)
Aborted
(gconftool-2:28079): GConf-WARNING **: Failed to load source "xml:readwrite:/home/root/.gconf": Failed: Could not make directory `/home/root/.gconf': No such file or directory
**
GConf:ERROR:gconftool.c:969:main: assertion failed: (err == NULL)
Aborted
(gconftool-2:28080): GConf-WARNING **: Failed to load source "xml:readwrite:/home/root/.gconf": Failed: Could not make directory `/home/root/.gconf': No such file or directory
**
GConf:ERROR:gconftool.c:969:main: assertion failed: (err == NULL)
Aborted
(gconftool-2:28081): GConf-WARNING **: Failed to load source "xml:readwrite:/home/root/.gconf": Failed: Could not make directory `/home/root/.gconf': No such file or directory
**
GConf:ERROR:gconftool.c:969:main: assertion failed: (err == NULL)
Aborted
(gconftool-2:28082): GConf-WARNING **: Failed to load source "xml:readwrite:/home/root/.gconf": Failed: Could not make directory `/home/root/.gconf': No such file or directory
**
GConf:ERROR:gconftool.c:969:main: assertion failed: (err == NULL)
Aborted
(gconftool-2:28083): GConf-WARNING **: Failed to load source "xml:readwrite:/home/root/.gconf": Failed: Could not make directory `/home/root/.gconf': No such file or directory
**
GConf:ERROR:gconftool.c:969:main: assertion failed: (err == NULL)
Aborted
(gconftool-2:28084): GConf-WARNING **: Failed to load source "xml:readwrite:/home/root/.gconf": Failed: Could not make directory `/home/root/.gconf': No such file or directory
**
GConf:ERROR:gconftool.c:969:main: assertion failed: (err == NULL)
Aborted
(gconftool-2:28085): GConf-WARNING **: Failed to load source "xml:readwrite:/home/root/.gconf": Failed: Could not make directory `/home/root/.gconf': No such file or directory
**
GConf:ERROR:gconftool.c:969:main: assertion failed: (err == NULL)
Aborted
我的代码有问题吗?