skip to Main Content

I downloaded (mdldec_linux_amd64) and (mdldec_linux_i386)

and placed them somewhere in cPanel / Files Manager / HTML folder

How to call this program from Call.PHP ?

I try something like below

shell_exec ("mdldec_linux_amd64 parameter1 parameter2");

can someone help me on this?

2

Answers


  1. Executing commands from php is not recommended, this might bring security issues. If you don’t have an option here are 2 examples:

    You should try to use the full path for the file you want to execute:

    shell_execute("/usr/local/mdldec_linux_amd64 parameter1 parameter2");
    

    Assuming that the file is the /usr/local folder

    Also you can use exec and get the last returned line from the executed command. and also the full output

    $output = array();
    $lastLine = exec("/usr/local/command",$output);
    

    And you might be able to debug better and have more information

    Login or Signup to reply.
  2. Executing a binary from PHP employing shell_exec or analogous functions is clear-cut and your example nearly has it. There are a handful of considerations and requisites that need to be taken into account:

    1. File Permissions: Certify that the PHP process possesses execution rights on the binary. You may need to chmod +x mdldec_linux_amd64 or chmod +x mdldec_linux_i386 to grant execution permissions.

    2. Absolute Path: Utilize the absolute path to the binary within your shell_exec call. PHP might not know where to locate your binary if you don’t inform it explicitly. For instance, instead of "mdldec_linux_amd64 parameter1 parameter2" it would be "/full/path/to/mdldec_linux_amd64 parameter1 parameter2".

    3. Safe Mode: Inspect if PHP is operating in Safe Mode (this is a configuration in php.ini). If it is, then the binary must reside in the directory specified via the safe_mode_exec_dir setting.

    4. Disabled Functions: Furthermore, ascertain that shell_exec function isn’t disabled. Some shared hosts deactivate potentially dangerous functions. You can verify this in the "disable_functions" directive within the php.ini file.

    Assuming your PHP setup permits you to use shell_exec, your PHP code would appear something like this:

    <?php
    $output = shell_exec('/full/path/to/mdldec_linux_amd64 parameter1 parameter2');
    echo "<pre>$output</pre>";
    ?>
    

    Replace /full/path/to/ with the actual path where you uploaded the file, and parameter1 parameter2 with the actual parameters you desire to pass to your program.

    Employing functions such as shell_exec can be perilous, because they allow PHP to execute arbitrary commands on the server. So only utilize them when absolutely necessary, and ensure to validate and sanitize all inputs to prevent potential security hazards.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search