Php: Running a python script using blender from a php project using cmd commands

别等时光非礼了梦想. 提交于 2019-12-11 21:06:24

问题


I need to run in cmd a python script for blender from blender and print the result from a php project, but I don't get the all result.

Here is my code:

$script = "C:\Users\madalina\Desktop\workspace\script.py";
$blander_path = "C:\Program Files\Blender Foundation\Blender";
$output = shell_exec("cd $blander_path && blender -b -P script.py -- $json");
print_r($output);

and here is what I receive:

found bundled python: C:\Program Files\Blender Foundation\Blender\2.69\python Blender quit

And here is what i get when i run the same script directly from my cmd

How can a get the same response when I when the same script from my php project? (I use blender 2.69)


回答1:


I resolve the problem. I changed the system_exec command with exec, put the json object in quotes.

this is my code now:

$json = str_replace("\"", "\\\"",  json_encode($jsonArray));
$script = "C:\Users\madalina\Desktop\workspace\script.py";
$blander_path = "C:\Program Files\Blender Foundation\Blender";
$output = exec("cd $blander_path && blender -b -P $script -- \"$json\"", $data);
print_r($data);


来源:https://stackoverflow.com/questions/23563809/php-running-a-python-script-using-blender-from-a-php-project-using-cmd-commands

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!