Page 1 of 1

run executable file on server

Posted: Tue Jun 01, 2010 12:28 pm
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.

Re: run executable file on server

Posted: Tue Jun 01, 2010 12:31 pm
by AbraCadaver

Code: Select all

exec()

Re: run executable file on server

Posted: Tue Jun 01, 2010 12:53 pm
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.

Re: run executable file on server

Posted: Tue Jun 01, 2010 12:57 pm
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/.

Re: run executable file on server

Posted: Tue Jun 01, 2010 1:34 pm
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

Re: run executable file on server

Posted: Tue Jun 01, 2010 1:52 pm
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]

Re: run executable file on server

Posted: Tue Jun 01, 2010 2:28 pm
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.

Re: run executable file on server

Posted: Tue Jun 01, 2010 2:34 pm
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]

Re: run executable file on server

Posted: Tue Jun 01, 2010 2:40 pm
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.

Re: run executable file on server

Posted: Tue Jun 01, 2010 2:44 pm
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.

Re: run executable file on server

Posted: Tue Jun 01, 2010 2:47 pm
by papa_smurf
As far as I can see neither bit of code did anything at all.

Re: run executable file on server

Posted: Tue Jun 01, 2010 2:52 pm
by AbraCadaver

Code: Select all

error_reporting(E_ALL);
ini_set('display_errors', '1');

Re: run executable file on server

Posted: Tue Jun 01, 2010 3:00 pm
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

Re: run executable file on server

Posted: Tue Jun 01, 2010 3:08 pm
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.

Re: run executable file on server

Posted: Tue Jun 01, 2010 3:09 pm
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.