0

I'm using php on WAMP. I'm trying to run an external program prog.exe under directory abc which takes one numeric parameter. the following command on DOS command line works fine

c:\abc\prog.exe 1234

but when I do it in php script it doesn't run.

$val="1234";
$comm = passthru("C:\abc\prog.exe ".$val)

but

$comm = passthru("dir");
echo $comm; 

works fine.

I'm running Windows 7.

P.S I've also tried system() and shell_exec()

6
  • What do you mean by 'it doesn't run'? As in the prog.exe is not getting the arguments? Commented Jun 12, 2012 at 19:12
  • the page seems to be loading but nothing happens until timeout.. Commented Jun 12, 2012 at 19:13
  • prog.exe is getting the argument.. it I do echo (whatever I'm passing through system) and then run it in command line, its fine.. Commented Jun 12, 2012 at 19:14
  • What's your program do? If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends. here Commented Jun 12, 2012 at 19:14
  • Answer from @Kolink should solve it :) Commented Jun 12, 2012 at 19:15

1 Answer 1

3

\ needs to be escaped as \\, or else you should use single quotes.

EITHER:

passthru("C:\\abc\\prog.exe ".$val);

OR:

passthru('C:\abc\prog.exe '.$val);
Sign up to request clarification or add additional context in comments.

8 Comments

@bsdnoobz Um... I don't think so?
Or passthru("C:/abc/prog.exe $val");
@Kolink oops, you're right. I didn't notice the single-quote.
@Kolink Both do not work.. Can it be a permission issue or something.. What should be the equivalent of chmod in windows. Do it have to give abc.exe execution rights..
Consider running your script through PHP's CLI. That way you should be able to see anything it's doing, as well as kill it if it takes too long.
|

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.