PHP:使用cmd命令从php项目中使用Blender运行python脚本 [英] Php: Running a python script using blender from a php project using cmd commands

查看:76
本文介绍了PHP:使用cmd命令从php项目中使用Blender运行python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在cmd中为Blender中的Blender运行python脚本,并从php项目中打印结果,但是我没有得到全部结果.

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.

这是我的代码:

$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);

这是我收到的信息:

找到捆绑的python:C:\ Program Files \ Blender Foundation \ Blender \ 2.69 \ python Blender退出

这是我直接从cmd运行相同脚本时得到的结果

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

当我从php项目中获得相同的脚本时,如何获得相同的响应?(我使用Blender 2.69)

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

推荐答案

我解决了这个问题.我用exec更改了system_exec命令,将json对象放在引号中.

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

这是我的代码:

$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);

这篇关于PHP:使用cmd命令从php项目中使用Blender运行python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆