Running program in php

Discussion in 'PHP' started by makhan, Jun 16, 2007.

  1. #1
    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');
    ?>
     
    makhan, Jun 16, 2007 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    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 ?
     
    krakjoe, Jun 16, 2007 IP
  3. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #3
    i think you might want shell_exec()
     
    ansi, Jun 16, 2007 IP
  4. makhan

    makhan Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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.
     
    makhan, Jun 16, 2007 IP
  5. InFloW

    InFloW Peon

    Messages:
    1,488
    Likes Received:
    39
    Best Answers:
    0
    Trophy Points:
    0
    #5
    InFloW, Jun 16, 2007 IP
  6. makhan

    makhan Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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.
     
    makhan, Jun 16, 2007 IP
  7. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #7
    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.
     
    ansi, Jun 16, 2007 IP
  8. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #8
    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.
     
    krakjoe, Jun 17, 2007 IP
  9. makhan

    makhan Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    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)
     
    makhan, Jun 17, 2007 IP
  10. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #10
    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 ......
     
    krakjoe, Jun 18, 2007 IP