通过exec()运行多个命令

时间:2014-04-09 08:16:30

标签: php python exec blender var

我需要将一个变量从php传递到blender中的python脚本。

基本上这应该有效:

exec("start cmd /k cd C:\Blender & set arg1='file' & blender -P [path to python file]");

相反,它只是将目录更改为C:\ Blender并停止。好像php的exec()不喜欢使用“&”彼此之后运行多个命令。

我假设这是因为当我打开cmd我的自己并输入:

cd C:\Blender & set arg1='file' & blender -P [path to python file]

打开blender并运行python脚本,打印arg1,(文件)。

有没有人有任何想法如何使用php中的exec()运行多个命令。或许我应该尝试一种不同的方法将php变量传递给blender python脚本。

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

您可以使用escapeshellarg。 当使用它时,它将整个参数视为单个安全参数。

所以你可以使用,

$variableToPass = "start cmd /k cd C:\Blender & set arg1='file' & blender -P [path to python file]";
exec(escapeshellarg($variableToPass));

希望这有帮助。