简体   繁体   中英

Running a blender script on linux hosting

I am currently working on a web app which spits out a .stl file in blender. I have used php and I am calling the script in php using exec(). Please look at the code below. I found the code from Php: Running a python script using blender from a php project using cmd commands

$script = "C:\\xampp\\htdocs\\test\\test.py";
$blender_path = "C:\Program Files\Blender Foundation\Blender";

$output = exec("cd $blender_path && blender -b -P $script", $data);
echo "<pre>";
print_r($data);
echo "</pre>";

And all works well locally. I uploaded the content to my site(Linux hosting), Uploaded Blender(Linux - https://www.blender.org/download/ ) changed the paths and nothing happens. It doesn't even output any errors. Is there a separate command line code for linux? I am not used to using Linux and I have been struggling with this for the past 3 days.

Any help is appreciated.

I can think of two possibilities. The first is the path names, on linux there is no drive letters a path should be something like /home/aniket/tests/blendtest

The second relates to running a program, I would expect an error but you may have to look into log files to find it or increase the verbosity of php. The first point is that a file needs permissions set to be executable, this would involve chmod +x blender or maybe using your ftp software to set this, it is often represented as X within a permissions string like RWXRWXRWX . The second point is the way commands are found on a *nix system, there is a PATH environment variable that lists directories to look for a command, the current directory is not in that list by default and I wouldn't expect a hosting company to add it.

$script = "/home/aniket/test1/test.py";
$blendexe = "/home/aniket/blender2.76/blender";

$output = exec("$blendexe -b -P $script", $data);
echo "<pre>";
print_r($data);
echo "</pre>";

On *nix systems ./ represents the current directory, so you may also have luck using

$output = exec("cd $blender_path && ./blender -b -P $script", $data);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM