0

I am running PHP 5.2.14 on Apache/2.2.16 (Win32) and I have a script to run a shell command, which when tested in the command prompt works well but in browser mode (html), it doesn't.

Scripts:

mybatfile.bat

REM ...
REM process some folder details
REM code which does not work in browser mode but works in cmd mode
C:/somfolder/bin/mysqldump -u abc -pabcdef --result-file="C:/Apache22/somfolder/DBbackup/DBbackup.%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%.sql" --dump-date  --log-error="C:/Apache22/somfolder/DBbackup/DBbackup.%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%.log" dbname > dboutputresult.txt

REM process result of savedfile

calltobatfile.php

//process some folder information
$file = file_get_contents($folderroot."/exec/mybatfile.bat");
//var_dump($file);
    $strarr = explode("\n", $file);
    foreach($strarr as $line){
      if(strlen($line)>1){
        var_dump("line: ".$line."\n"); 
        $output = shell_exec($line);
        print_r($output);
     }
   }

//process result of savedfile additional information

What can I try next?

2
  • 1
    does the webserver userid have the rights to do whatever is being done in that batch file? working from cli but not from webserver is usually a permissions/path problem. Commented Oct 22, 2012 at 16:20
  • thanks for the suggestions. It was definitely a permission issue as it now works after tweaking with the folder permissions. Commented Oct 22, 2012 at 17:18

3 Answers 3

3

Check the permissions to run it as a server. You can run this as owner, but there can be no possibilities to run it as other user - in your example as apache.

Sign up to request clarification or add additional context in comments.

Comments

2

here is a my code and its working fine.

$result = mysqli_query($mysqli_link,'SHOW VARIABLES LIKE \'%basedir%\';');
    $row = mysqli_fetch_array($result);
    $pathtodump = "".$row['Value']."/bin/mysqldump";    
    $command= "$pathtodump -h " . $db_host . " -u " . $db_user . " -p".$db_pass. " " . $db_dbname . "> filename.sql";
    exec($command);

Note try to give mysqldump.exe file name with full path

Comments

1

Maybe is a permission related issue? In your command line you may be using other User rather than the web one which may not have the required permissions to execute or write in C:/Apache22/somfolder/DBbackup/ or dboutputresult.txt

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.