Calling a matlab exec with php script?
8 views (last 30 days)
Show older comments
Hello,
I have an executable file which is generated by matlab. This file runs a simple calculation and produces a plot (and saves that plot as a bmp file). The exec works fine when used stand-alone (i.e. when I double click). However the problem arises when I try to call the exec from a php script. The calculation still runs and I get the output but the plots dont get generated. When I search the folder wher the plots are supposed to be stored at, I see the file but they are all corupted (bmp file with 1kb size and cannot be seen).
As I said, the calculation still runs when called from the script, just the plots get corrupted and I dont know why.
I would appreciate if any of you has an idea?
PS: I am using the below script for calling the exec
<?php
exec("filename.exe");
?>
1 Comment
Kaustubha Govind
on 8 Feb 2012
Some of us may not be familiar with PHP - could you maybe just try running the executable from the system shell and check if you see the same symptoms?
Answers (3)
Jason Ross
on 9 Feb 2012
Try running something simple like
system('set')
this will tell you the environment you get when running from command prompt, from the MATLAB desktop and from within PHP. Look for differences there. If the PHP environment is different, try and make it the same as the others by setting environment variables and see if this makes a difference.
0 Comments
Jason Ross
on 8 Feb 2012
Which user context is this script executing as? If this is part of a web server, it's possible that it could be LocalSystem or IIS_USER. These users may not have access to a desktop, so if you are doing something that uses something with reliance upon screen geometry, they may be returning nonsense.
Look at what the exec() call is doing in PHP. Is it simply calling a command shell, or is it executing the command using some other method? The environment provided by the exec() may be missing some things that are required by your plot.
You may want to consider creating a debug log where you write the values of things when running under the php context as well as the command window. It's likely that there will be some difference that's causing the failures.
See Also
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!