954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Run .exe file using PHP on Windows

I need to execute a .exe file located in C:\Program Files\ABC\test.exe on my windows machine using PHP. I have installed WAMPP/XAMPP to run PHP. I have tried the exec() system() shell_exec() but I'm unable to run the file. Can someone help me with the exact code?

tAALz
Newbie Poster
10 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

have you tried passthru() it is similar to the system command. If it does not work then it is probable that these command are disabled by your hosting provider.

sam-i-am
Newbie Poster
23 posts since Aug 2010
Reputation Points: 10
Solved Threads: 2
 

Can you provide me the exact code of passthru() ?
I am using WAMPP on my local machine to test it. If the commands are disabled, can you help me identify and enable them?

tAALz
Newbie Poster
10 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

Why would you want to run exe on local file system?
Can't it be accomplished via pure PHP solution?

evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
 

I need a execute a windows application from PHP. My whole website will be placed on a web hosting, just one process will run from my local system which will act as a web server and execute the windows application.

tAALz
Newbie Poster
10 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 
system("*:/***.exe");
zark_yoc
Newbie Poster
15 posts since Sep 2010
Reputation Points: 10
Solved Threads: 1
 

$result=passthru('dir');
print $result;

more info on
http://php.net/manual/en/function.passthru.php

sam-i-am
Newbie Poster
23 posts since Aug 2010
Reputation Points: 10
Solved Threads: 2
 

I did some experimenting with Exec.

I had no problem starting a local program with Exec with one exception. If the path name contains a blank, I wasn't able to get it to work. Even if the actual program name contains a blank, it works. One simple example that worked was:

$addr = "c:/Temp/TSP/TSP2.exe";
exec ($addr,$output, $return);

$output has the display output from the program if it is writing to the current window. If it opens in its own window then you see the output there. An example of getting the output from the current window is as follows:

exec("ping google.com", $output, $return);
    echo "The command returned $return, and output:\n";
    echo "<b>PING </b><pre>";
    echo "<pre>";
    var_dump($output);
    echo "</pre>";
chrishea
Nearly a Posting Virtuoso
1,428 posts since Sep 2008
Reputation Points: 210
Solved Threads: 230
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: