0

My setup is as follows: Windows 7, XAMPP with Apache and PHP enabled I have a PHP script in which I call an external program to do run a conversion. This external program is an EXE file, which requires 3 attributes:

  • The source file
  • The destination file
  • Additional flags (conversion type etc)

When I use the command line tool built into XAMPP to execute my script, everything works fine. But when I use the exec() function in my PHP script, no output file is created. I'm pretty sure the conversion is actually happening (it takes about 5 seconds, about the same time it takes to run the PHP script).

I think it's a permissions thing, so I already moved the EXE file to the same folder as my PHP file and adjusted the permissions of the entire folder (I granted all permissions to all users). I also disabled the Windows UAC and tried to put the command in a BAT file. The file just is not created.

Any help or tips would be greatly appreciated!

My PHP code is as follows:

exec('c:\converter.exe c:\src.txt c:\dst.txt -f', $output);
print_r($output);

When I print out $output, the array turns out to be empty. When I put the exact same command in Command Prompt, the code works like a charm (no syntax errors). I use absolute paths as well.

Flock Dawson
  • 1,842
  • 4
  • 22
  • 34

2 Answers2

0

Try to copy your executable file in same folder as your application. try

    exec("script.exe src.txt dst.txt", &$output);
    echo $output;

also, do not forget to use escapeshellcmd() to add some security to your application.

  • Thank you for your advice! No dice, though. I don't think it's a permission issue anymore, as I used the XAMPP shell and found out my command does what it has to in this XAMPP environment. It still won't work when I use it in a PHP script. Totally puzzeled :S – Flock Dawson Jul 12 '13 at 15:38
0

Thank you very much for your input! As it turns out, it was Windows issue caused by the 'Interactive Services Detection' feature. Apache was running as a system service, which prevented calls to external programs (with a GUI). I disabled the run-as-service feature in XAMPP, which solved the problem. A more thorough explanation can be found here: http://php.net/manual/en/book.exec.php

Flock Dawson
  • 1,842
  • 4
  • 22
  • 34