run executable file on server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
papa_smurf
Forum Newbie
Posts: 14
Joined: Tue Jun 01, 2010 12:22 pm

run executable file on server

Post by papa_smurf »

Hey all,

My dilemma is that I need to run a simple .exe file on my server. All it does is take an input txt file, runs some calculations and spits out data into an output txt file. Those files are named as:

SEA-R001-IN-1.txt
SEA-R001.exe
SEA-R001-OUT.txt

Does anyone know how I can write code to do this for me?

Thanks.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: run executable file on server

Post by AbraCadaver »

Code: Select all

exec()
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
papa_smurf
Forum Newbie
Posts: 14
Joined: Tue Jun 01, 2010 12:22 pm

Re: run executable file on server

Post by papa_smurf »

Ok so using that exec() command would this work:

Code: Select all

<?php
exec('/templates/paperchine/programs/SEA-R001/SEA-R001.exe, /templates/paperchine/programs/SEA-R001/SEA-R001-IN-1.txt, /templates/paperchine/programs/SEA-R001/SEA-R001-OUT.txt');
?>
Thats exactly how I would type it into command prompt and run it. Just tell me if i'm wrong. I'm still new to a lot of this stuff.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: run executable file on server

Post by AbraCadaver »

It should work, if: the webserver has permission to run that exe and if it has permission to write the out file to /templates/paperchine/programs/.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
papa_smurf
Forum Newbie
Posts: 14
Joined: Tue Jun 01, 2010 12:22 pm

Re: run executable file on server

Post by papa_smurf »

Ok, so no go with that last try.

I have my files located at:
http://www.bffireworks.com/templates/pa ... 1-IN-1.txt
http://www.bffireworks.com/templates/pa ... A-R001.exe
http://www.bffireworks.com/templates/pa ... 01-OUT.txt

did I screw up in how I wrote my exec() php?

When I use this program I save all the files in my c drive and use command prompt and type:

C:\>SEA-R001.exe SEA-R001-IN-1.txt SEA-R001-OUT.txt
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: run executable file on server

Post by AbraCadaver »

Your paths aren't correct. They most likely are similar to this, but you'll have to check. I assume the server is linux?
[text]/var/www/templates/paperchine/programs/SEA-R001/[/text]
Do this to see:

Code: Select all

exec("pwd");
Or if your PHP script is in the directory above templates, then just leave off the preceding slash:
[text]templates/paperchine/programs/SEA-R001/[/text]
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
papa_smurf
Forum Newbie
Posts: 14
Joined: Tue Jun 01, 2010 12:22 pm

Re: run executable file on server

Post by papa_smurf »

So I ran:

Code: Select all

<?php
echo exec("pwd");
?>
from testing.php (located in same folder as the program I want to execute) and I got the following as a result:

Code: Select all

/var/www/vhosts/bffireworks.com/httpdocs 
I'm also using Joomla to set up my site, if that affects anything.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: run executable file on server

Post by AbraCadaver »

papa_smurf wrote:So I ran:

Code: Select all

<?php
echo exec("pwd");
?>
from testing.php (located in same folder as the program I want to execute) and I got the following as a result:

Code: Select all

/var/www/vhosts/bffireworks.com/httpdocs 
I'm also using Joomla to set up my site, if that affects anything.
So all of the paths would probably be like this:
[text]/var/www/vhosts/bffireworks.com/httpdocs/templates/paperchine/programs/SEA-R001/[/text]
Or you could just make it relative like I said in the previous post (this would be more portable):
[text]templates/paperchine/programs/SEA-R001/[/text]
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
papa_smurf
Forum Newbie
Posts: 14
Joined: Tue Jun 01, 2010 12:22 pm

Re: run executable file on server

Post by papa_smurf »

So if I wrote the php correctly it should look like:

Code: Select all

<?php 

exec('/var/www/vhosts/bffireworks.com/httpdocs/templates/paperchine/programs/SEA-R001/SEA-R001.exe /var/www/vhosts/bffireworks.com/httpdocs/templates/paperchine/programs/SEA-R001/SEA-R001-IN-1.txt /var/www/vhosts/bffireworks.com/httpdocs/templates/paperchine/programs/SEA-R001/SEA-R001-OUT.txt');

?>
Right? Like I said before, this is all new to me. Hope I'm not frustrating you too much! Thanks for all your help thus far.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: run executable file on server

Post by AbraCadaver »

Does that work?

I would try:

Code: Select all

passthru('./templates/paperchine/programs/SEA-R001/SEA-R001.exe ./templates/paperchine/programs/SEA-R001/SEA-R001-IN-1.txt ./templates/paperchine/programs/SEA-R001/SEA-R001-OUT.txt');
And see if you get errors.

FYI passthru() is exec() but outputs all of the results.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
papa_smurf
Forum Newbie
Posts: 14
Joined: Tue Jun 01, 2010 12:22 pm

Re: run executable file on server

Post by papa_smurf »

As far as I can see neither bit of code did anything at all.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: run executable file on server

Post by AbraCadaver »

Code: Select all

error_reporting(E_ALL);
ini_set('display_errors', '1');
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
papa_smurf
Forum Newbie
Posts: 14
Joined: Tue Jun 01, 2010 12:22 pm

Re: run executable file on server

Post by papa_smurf »

Not sure what that was supposed to do, but it didn't do anything when I added it to the other code
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: run executable file on server

Post by AbraCadaver »

papa_smurf wrote:Not sure what that was supposed to do, but it didn't do anything when I added it to the other code
That should go at the top of the script and should turn on error reporting. If you don't get errors then I can't help you.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: run executable file on server

Post by AbraCadaver »

Also, if that's a windows executable then its probably not going to run on linux. Maybe if you installed WINE, but that's usually not an option if this is shared hosting.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply