Using PHP exec() to kick off a blender render

Don’t know if anyone has managed to acheive this ( although BRender looks like it does this ).

I’m just trying to use PHP start blender in command-line mode and render an object on for display on my webserver.

I’ve got the command-line correct ( as in it renders the file exactly as I want when run from a command prompt ) but any variant of PHPs exec() function just fails. The weird thing is that it definitely seems to be executing blender, because if I pass in malformed arguments I get a correct response -eg something like ‘Blender could not open the file blah blah’ then ‘Blender quit’

This is all on Win7, running apache 2.2 and php5.2 BTW. Apologies that its not blender-specific, but its quite closely related i think!

I’ve also added a stackoverflow question here with a bit more detail, if anyone here uses SO and can answer the points could be yours!

any help would be greatly appreciated :slight_smile:

I am having a very similar problem:

Blender (2.80) is installed on AWS in directory /home/ec2-user.

php is run on the same server from /var/www/html/wed

I have access through cli:

wed]$ ls /home/ec2-user

Lists contents of /home/ec2-user.

And access through php:

<?php<br />
$output = shell_exec('ls /home/ec2-user'); 
echo "<pre>$output</pre>"; 

Lists contents of /home/ec2-user.

I can run Blender through cli:

wed]$ /home/ec2-user/blender280/blender -b -noaudio proj007/font-sample.blend --python proj007/

Runs the blender script (proj007/ and outputs 663 png files to /var/www/html/wed/fonts.

But not through php:

$output = shell_exec('/home/ec2-user/blender280/blender -b -noaudio proj007/font-sample.blend --python proj007/'); 
echo "<pre>$output</pre>"; 


Commands are copied and pasted so there is no typo.

If you can answer MeiaLua’s on SO, double your points by answering mine:

Instead of:
$output = shell_exec(’/home/ec2-user/blender280/blender -b -noaudio proj007/font-sample.blend --python proj007/’);

I used:
$output = shell_exec(‘cd /home/ubuntu/ && blender280/blender -b -noaudio proj007/font-sample.blend --python proj007/’);

This works.