2

I'm running Apache 2.2.17 and PHP 5.3.5 on a Windows 7 64-bit machine.

I have noticed that if I try to use exec(), system() or any of the other functions for executing a system command through PHP it does not work. The exact same commands will work if you paste them into the command line window. This seems to affect all programs which are not the simplest of command line programs. Even a simple attempt to open notepad will not work e.g. system('C:/Windows/system32/notepad.exe').

What could be causing this?

Thanks

3
  • 2
    Do error_reporting(E_ALL); at beginning of your script and retry. What you see? What logs say? Commented Aug 28, 2012 at 16:35
  • fix php,ini - and that give the various options you desire. Commented Aug 28, 2012 at 16:39
  • Possibly the disable_functions option in php.ini. See adamish.com/blog/archives/123 Commented Aug 28, 2012 at 16:43

2 Answers 2

1

Read it

E.g.

<?php exec('C:\\WINDOWS\\system32\\psexec.exe \\192.168.1.224 -u myuser ... etc.

I also see the following in the referenced discussion:

quote; In Windows, exec() issues an internal call to "cmd /c your_command". This implies that your command must follow the rules imposed by cmd.exe which includes an extra set of quotes around the full command:

http://ss64.com/nt/cmd.html

Current PHP versions take this into account and add the quotes automatically, but old versions didn't. endquote:

There is also some discussion about setting the Windows permissions on the folder where the command resides, which I can imagine could be quite the heartburn on a Vista or Windows 7 machine. You may need to allow access to the WAMPserver itself somehow.

EDIT:

The only other suggestions I can think of are:

  • grant FULL access to EVERYBODY on the executable file AND the folder path that contains it

  • check the server error log to see if there's an error message with any useful information

one more thing occurs to me:

  • copy your executable file to C:\WINDOWS\SYSTEM32, and run it as if it were "ping".

good luck!

Source(s): Recommended reading: a lot of people discuss the solutions to a lot of problems

http://php.net/manual/en/function.exec.php

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

Comments

0

Unfortunately none of these solutions worked for me. I have changed my approach and will not be using PHP to launch the executable.

1 Comment

fair enough. sometimes it's a case of using the right tool for the job rather than forcing the wrong tool to do the job.

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.