Jump to content
The Uniform Server Community
x_maras

run an exe with php

Recommended Posts

Hi!

 

I want to make a page that reads an xml file and presents some data.

the xml is exported from a "file.exe" and also takes a parameter "param.wpf".

 

I did it with python using the os module, but I dont know if is it possible to run an exe this way from php

and also with the uniform server.

 

If it's possible they both have to be in the server right?

 

If you know something about this, a command or a link or an example would be great :unsure: , I would be gratefull.

 

Thanks

Share this post


Link to post
Share on other sites

The following example may be of help! I am using test.bat replace it with your .exe

 

Save the following test.bat to any folder (it does not need to be in server root) for example c:\test\test.bat It’s a simple batch file that just echos a few lines,

 

@echo off

if "%1"=="param.wpf" goto :REV

echo 123

echo 456

echo 789

goto :END

:REV

echo 987

echo 654

echo 321

:END

exit

 

Save the following test.php to root folder www

 

<?php

$output = `c:/test/test.bat param.wpf`;

echo "

$output
";

 

$output = `c:/test/test.bat`;

echo "

$output
";

 

$output = `dir *.php`;

echo "

$output
";

?>

 

Note: The $output’s are not using quotes but backticks, in other words they are running system commands.

 

The first demonstrates passing a parameter to the batch file (executable). Second just runs the batch file with no parameters. The last one demonstrates running a standard dos command and passing a parameter (if your executable is on a system path there is no need to specify a path)

 

This PHP page may be of use

 

Al the best

Ric :unsure:

Share this post


Link to post
Share on other sites

be carefull of using backtick operations. safe mode might be a problem. you should also see into the other exec commands. (but the backtick way IS the easiest)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...