1

I have tried calling a windows program several ways and I have gotten the same result each time.

The program opens up on my machine (without a GUI) but never closes each means that the browser is forever loading.

Though when executing the query string manually through the command line prompt the program closes. Not only that, but the program doesn't actually execute

(it is just launched i.e. there aren't any results).

I just want to know the proper way of starting a program with switches through PHP.

Here is the query string that works (closes the program after executing):

"C:\Program Files (x86)\Softinterface, Inc\Convert PowerPoint\ConvertPPT.exe" /S 
"C:\Users\Farzad\Desktop\upload\test.ppt" /T "C:\Users\Farzad\Desktop\upload\test.png" /C 18
5
  • You should first try moving data files outside your profile (e.g., create a C:\test directory) to discard permission issues. Commented Mar 8, 2011 at 16:40
  • @Alvaro, that won't necessarily fix the issue. Commented Mar 8, 2011 at 16:42
  • @Brad, troubleshooting requires being methodical. You can't just test everything at once randomly. Commented Mar 8, 2011 at 16:44
  • @Alvaro, I am simply pointing out that moving everything outside of the profile won't rule out permissions issues. Of course it should be one of the first things to check, but he would be better off trying out appropriate permissions. Commented Mar 8, 2011 at 16:47
  • @Brad, Windows user profiles are restricted to their owner: they will never be writeable by Apache with default settings. However, it may not be a permissions issue after all. I think it's easier to just test in another folder (something that takes 30 seconds and doesn't have side effects) rather than reconfiguring (and maybe misconfigure) your development environment. Commented Mar 8, 2011 at 16:55

4 Answers 4

2

If the program never closes, then PHP can't return a value from exec(). The program must close. Chances are there is a problem accessing your files on your desktop in this manner. It will be executed with whatever permissions the webserver has defined.

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

You might consider the advanced functionality of proc_open(). It will give you access to all the necessary pipes, but I don't think that will help you in this situation.

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

6 Comments

So does this mean that I am supposed to give read/write and execute permissions of the .exe file to anyone?
No, you would be better off configuring your web server (IIS I'm assuming?) to run this script as a specific user, and give that user account access.
Well I am using local host as my web server (WAMP) to test it
So, Apache then. You're running it as a service? You can modify the service properties to run as another user. See stackoverflow.com/questions/2683766/…
You might also try running Apache as yourself (just start httpd.exe manually) for testing.
|
1

If the target directory on your Windows machine is C:\Program Files (x86)\Softinterface, Inc\Convert PowerPoint\ConvertPPT.exe, you need to double-quote the directories that have space character within them.

To translate it into php terms, it should be like this:

$directory = 'C:\"Program Files (x86)"\"Softinterface, Inc"\"Convert PowerPoint"\ConvertPPT.exe';

$command = $directory . ' enter your arguments here';

exec($command, $output, $return_var);

// if $return_var == 0, you hit the jackpot.

2 Comments

I think you are incorrect. See php.net/manual/en/function.exec.php#101579. You don't need (and shouldn't) put double quotes around each directory. Just put some around the whole command, and only on PHP 5.2 and older. Plus, I don't think this is the issue anyway, as he said he can see the program running. If it had failed, it wouldn't block his PHP code.
It's nothing to do with exec command, it's to do with Windows themselves, especially Windows XP (I haven't used W7 or Vista for PHP testing). If a directory has spaces within the name, you quote the directory and resolve path issues. If you don't, the program that you try to invoke hangs. I came across the solution by trial and error, and it definitely works in my particular case so I shared with the OP.
0

The physical directory where your Windows desktop is stored belongs to your user profile folder. That means that other users (including the one Apache runs as, which is typical "Local System") won't have the appropriate permissions to read and write files on it. While you can adjust your Apache set-up to make it run with your own user, Farzad, it's more common to put web applications in an entirely different directory tree. It may happen that ConvertPPT.exe just stalls because it's trying to write a file at a location where it's not allowed. I suggest you create a top folder directory and make sure it's world-writeable (once finished, you can tighten these permissions if you like).

Once you discard (or confirm) that the issue is caused by lack of appropriate credentials, make sure you are escaping your command and arguments properly. See this link:

http://es2.php.net/manual/en/function.exec.php#101579

One more thing you can try is to close PHP sessions before issuing the call to exec():

http://es2.php.net/manual/en/function.exec.php#99781

Comments

0

You have probably run into this bug: http://bugs.php.net/bug.php?id=44994

which has been bothering me for ages, even today, on PHP 5.3.5.

It seems like there is some kind of deadlock between the error output of the program and the apache error log file handle into which the program is redirected to write its stderr output, making the program be stuck for ever until the apache processes are killed.

Also, when using passthru, or system, or the backtick operator, there's an intermediary "cmd.exe" process that is used to run the program in an invisible console, and I have seen this cmd process getting stuck without even running the program.

I don't really have a solution as of now, and it seems the bug, even though reproduced by many people, hasn't been resolved.

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.