0

我有一个 python 程序,我想在其中运行带有 truss 的 BSD 系统命令,以便我可以获得所做的系统调用的列表(open、stat 等)。例如,命令将是:

truss -S <application specific command>

我正在使用 subprocess.Popen(command, .., ..) 来调用命令。我将命令作为列表而不是字符串传递,因此我从 Python 获得了正确的编码。所以命令列表如下:

command = ['truss', '-S', <application specific command>]

但这给 truss 一个错误:

truss -S "ls -lrt"
truss: execvp  No such file or directory
truss: can not get etype: No such process

但是,如果我在没有上述引号的情况下运行相同的命令,它就会通过。当我将命令作为列表传递给 Popen 时,Python 添加类似于上面的引号,并且我需要这些引号才能使命令按预期工作。

解决这个问题的最佳方法是什么?

4

0 回答 0