通过exec()运行多个命令
我需要把一个变量从PHP传递到Blender里的Python脚本。
基本上应该是这样工作的:
exec("start cmd /k cd C:\Blender & set arg1='file' & blender -P [path to python file]");
但实际上它只是把目录改成了C:\Blender,然后就停了。看起来PHP的exec()函数不太喜欢用"&"来连续运行多个命令。
我这么猜测是因为当我自己打开命令提示符,输入:
cd C:\Blender & set arg1='file' & blender -P [path to python file]
它能打开Blender并运行那个Python脚本,打印出arg1(文件名)。
有没有人知道怎么在PHP的exec()里运行多个命令?或者我是不是应该尝试其他方法把PHP变量传给Blender的Python脚本。
谢谢大家的帮助!
1 个回答
0
你可以试试用 escapeshellarg 这个函数。当你使用它的时候,它会把你输入的整个参数当作一个安全的参数来处理。
所以你可以这样使用:
$variableToPass = "start cmd /k cd C:\Blender & set arg1='file' & blender -P [path to python file]";
exec(escapeshellarg($variableToPass));
希望这对你有帮助。