Hi I am trying to run a matlab script.(This script you can run from the command line by command 'matlab -r scriptname'). But when I use this command inside a system or exec I don't get any output, nor does the matlab opens and executes as it does in case of command line.. I am doing like <?php echo exec(' matlab -r scriptname'); ?>
The prototype for exec reads string exec ( string $command [, array &$output [, int &$return_var]] ) meaning you only get the last line of output in the return value, to store everything from a command call exec( 'command', $output ); data in an array in output, call echo implode("\r\n", $output ); to echo as a whole string. You have a space in your example there, that prolly shouldn't be there, and also be aware that you cannot execute all and any program with exec. What does metlab do there is probably a php equivalent function or not too hard to make one ?
Thanks guys, I don't want any output to be displayed or returned. I just want to execute command 'matlab -r scriptname' is it possible using php.
It is possible using shell_exec and assuming your host supports it. Here's an explanation of it via PHP http://php.net/manual/en/function.shell-exec.php manual. There are some others commands like exec which could do this as well.
Thanks, what do you mean host supports it. I have tried this and nearly all the program/command executions funtions but the command I am trying to run isn't running.
meaning that some functions are disabled for security reasons. these can be set in php.ini so it's really up to the host to allow it or not.
I told you already, you cannot execute all and every program that's not how it works, it's not suprising you cannot execute it.
But the thing is i am unable to execute simple commands like exec('date') so I thought that it is something else rahter than this particualr program. I have made sure that i am not using safe mode in php.ini file. I am on windows system and running apache, does this have anything to do with this.( I am doing everything on my own system so there is no issue of getting permission from host)
You wouldn't be able to execute date, it's an interactive command. Do you get output from <?php exec("dir", $output ); echo implode("\r\n", $output ); ?> PHP: And also, have you tried specifying the full path to matlab.exe ?? I don't have it installed but would assume it's not installed as a system binary ......