execute exe file from php script

Hi i have a doubt how to execute exe file from php script? I tried Exec and shell_exec but its not responding.

That will probably be your host disabling it for security reasons.

[php]
if(exec(‘echo EXEC’) == ‘EXEC’){
echo ‘exec works’;
}
[/php]

Source

No host is enable only if condition working properly but its not executing exe file and it’s printing the content in echo

Ok, you’ll have to help us out a little here. What are you trying and what isn’t working? Any code for us to look at?

I tried code is

<?php if(exec('echo EXEC') == 'EXEC'){ exec("C:\Program Files\TextPad 7\TextPad.exe"); echo 'exec works'; } ?>

Well, first, you can NOT run an ‘executable’ file like a Windows file on a server. If you are using a local
server system such as WAMP or XAMP, then it might work. Running a PHP command on a server to start
a server command works well as you will see below, but, PHP is not designed to run Windows programs
although some can be started if they are installed on the server itself.

But, karthikatrector, here is a script that I use on my server for dumping a backup of the database.
It calls the MySQLi function to dump a database to a file. Then, it forces a download of the file
to start. It creates a backup file with a SQL extension. First it dumps all files with that extension,
creates a backup and then downloads it.

Very handy code. And, it does it by calling the server using the EXEC function. This should give you
an idea how to do it… Hope this helps!
[php]
// If the ADMIN requested a full backup of the database, this code creates it and starts it downloading…
if (isset($POST[“backup_database”])) {
// First, erase any old backups as those are no longer needed…
unlink("*.sql");
// Create a new full backujp
$filename='database_backup
’.date(‘y_m_d’).’.sql’;
$result=exec('mysqldump DB_NAME -uDB_USERNAME -pDB_PASSWORD > ’ . $filename);
// We now have a full backup of the database, start a download of the file to the local system…
header(‘Content-Type: application/download’);
header(‘Content-Disposition: attachment; filename=’ . $filename);
header("Content-Length: " . filesize($filename));
$fp = fopen($filename, “r”);
fpassthru($fp);
fclose($fp);
}
[/php]
NOTE: You have to put in the name of the database, it’s username and password like you do in your
connection string. If you only need to run a server command without the extra code, it is basically:
[php]
$result=exec('your server command goes here… ');
[/php]
Yes, it is that simple… There are many other ways to execute a server command. This one will return odd
results and therefore is not easy to know if the command worked correctly. The passthru function works
well in some cases. Here is a post that talks about which to use which gives you further knowledge…
http://stackoverflow.com/questions/732832/php-exec-vs-system-vs-passthru
Look at the third post in that link. You can click on each of the functions and it will take you to the php.net
site which talks about the one you click on. Very helpful info there!

Good luck…

One more thing…

If you EXECUTE an ECHO command, it will ECHO the text. That is what it does. It is correct.
If you want to run a server command, it should do it. You need to read up on the PHP.net site
the four or five ways to execute commands which are on the thread I posted to you.

Sponsor our Newsletter | Privacy Policy | Terms of Service