Welcome! Log In Create A New Profile

Advanced

[PHP] How to Execute Exe File from PHP

Posted by Alice Wei 
Alice Wei
[PHP] How to Execute Exe File from PHP
October 20, 2008 10:50PM
Hi,

Has anyone tried to execute an .exe file from PHP? I am
currently stuck in a situation where I cannot execute the script, and
all I am getting is a blank screen.

This is my code snippet used to execute the file:

//execute program
$a = @shell_exec("C:\Inetpub\wwwroot\test/test.exe");
echo $a;

The
program above is supposed to generate a file, so I can read from it. I
have previously set up a file, and I have no problems with reading the
file.
Can anyone please help me with the possible command to
execute the script? I tried CURL too, but it does not seem to be
working either.

Thanks a lot.

Alice



_________________________________________________________________
Search from any Web page with powerful protection. Get the FREE Windows Live Toolbar Today!
http://get.live.com/toolbar/overview
Dan Joseph
Re: [PHP] How to Execute Exe File from PHP
October 20, 2008 10:55PM
On Mon, Oct 20, 2008 at 4:47 PM, Alice Wei <[email protected]> wrote:

>
>
>
> Hi,
>
> Has anyone tried to execute an .exe file from PHP? I am
> currently stuck in a situation where I cannot execute the script, and
> all I am getting is a blank screen.
>
> This is my code snippet used to execute the file:
>
> //execute program
> $a = @shell_exec("C:\Inetpub\wwwroot\test/test.exe");
> echo $a;
>
> The
> program above is supposed to generate a file, so I can read from it. I
> have previously set up a file, and I have no problems with reading the
> file.
> Can anyone please help me with the possible command to
> execute the script? I tried CURL too, but it does not seem to be
> working either.
>
> http://get.live.com/toolbar/overview


If you run the file from command line (dos prompt), does it output anything?

--
-Dan Joseph

www.canishosting.com - Plans start @ $1.99/month.

"Build a man a fire, and he will be warm for the rest of the day.
Light a man on fire, and will be warm for the rest of his life."
Stut
Re: [PHP] How to Execute Exe File from PHP
October 20, 2008 10:55PM
On 20 Oct 2008, at 21:47, Alice Wei wrote:
> Has anyone tried to execute an .exe file from PHP? I am
> currently stuck in a situation where I cannot execute the script, and
> all I am getting is a blank screen.
>
> This is my code snippet used to execute the file:
>
> //execute program
> $a = @shell_exec("C:\Inetpub\wwwroot\test/test.exe");
> echo $a;
>
> The
> program above is supposed to generate a file, so I can read from it. I
> have previously set up a file, and I have no problems with reading the
> file.
> Can anyone please help me with the possible command to
> execute the script? I tried CURL too, but it does not seem to be
> working either.

1) Remove the @ before the function call, it's hiding the error message!

2) \ needs to be escaped within double quotes, try replacing each one
with \\

3) Why are you mixing \'s and /'s? Dunno whether it matters, but it's
definitely better to stick to one or the other.

4) There is no 4!

-Stut

--
http://stut.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Daniel Brown
Re: [PHP] How to Execute Exe File from PHP
October 20, 2008 11:00PM
On Mon, Oct 20, 2008 at 4:51 PM, Stut <[email protected]> wrote:
>
> 4) There is no 4!

This is how the HTTP error code came about in the first place.
Someone heard someone else calling for your missing number.

"Four?!? Oh, four?!?"

--
</Daniel P. Brown>
http://www.parasane.net/ [New Look]
daniel.brown@parasane.net || danbrown@php.net

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Alice Wei
RE: [PHP] How to Execute Exe File from PHP
October 21, 2008 03:50AM
Hi,

Thanks for helping me out on this one. It turned out that after removing the @ sign, I found some errors I have during my exe compilation.
Now the file is working. Thanks.for the heads up, everyone.

Alice




Alice Wei, MIS

Programmer/Computer Application
Developer
ProCure Treatment Centers, Inc.
420 N. Walnut St.
Bloomington, IN 47404

812-330-6644 (office)
812-219-5708 (mobile)

[email protected](email)
http://www.procurecenters.com/index.php (web)



----------------------------------------
> Date: Mon, 20 Oct 2008 16:55:37 -0400
> From: parasane@gmail.com
> To: stuttle@gmail.com
> Subject: Re: [PHP] How to Execute Exe File from PHP
> CC: ajwei@alumni.iu.edu; php-general@lists.php.net
>
> On Mon, Oct 20, 2008 at 4:51 PM, Stut wrote:
>>
>> 4) There is no 4!
>
> This is how the HTTP error code came about in the first place.
> Someone heard someone else calling for your missing number.
>
> "Four?!? Oh, four?!?"
>
> --
>
> http://www.parasane.net/ [New Look]
> daniel.brown@parasane.net || danbrown@php.net

_________________________________________________________________
All-in-one security and maintenance for your PC.
Alice Wei
RE: [PHP] How to Execute Exe File from PHP
October 21, 2008 04:05PM
Hi, Guys: Sorry about bothering everyone about this problem. It seems strange that now I try to create some arguments after what I tried to execute, it does not give me a thing.
I get no error messages. No output file, and only a blank screen when I put the following snippet into the PHP file.
$a= shell_exec("./test.exe -m$market -d$length");
echo $a;
What is odd is, I tired doing this by using a dos command prompt, it works entirely. Could anyone please give me a hint on what problem I am having now?
Thanks for the heads up.

Alice
> CC: php-general@lists.php.net
> From: stuttle@gmail.com
> To: ajwei@alumni.iu.edu
> Date: Mon, 20 Oct 2008 21:51:23 +0100
> Subject: Re: [PHP] How to Execute Exe File from PHP
>
> On 20 Oct 2008, at 21:47, Alice Wei wrote:
> > Has anyone tried to execute an .exe file from PHP? I am
> > currently stuck in a situation where I cannot execute the script, and
> > all I am getting is a blank screen.
> >
> > This is my code snippet used to execute the file:
> >
> > //execute program
> > $a = @shell_exec("C:\Inetpub\wwwroot\test/test.exe");
> > echo $a;
> >
> > The
> > program above is supposed to generate a file, so I can read from it. I
> > have previously set up a file, and I have no problems with reading the
> > file.
> > Can anyone please help me with the possible command to
> > execute the script? I tried CURL too, but it does not seem to be
> > working either.
>
> 1) Remove the @ before the function call, it's hiding the error message!
>
> 2) \ needs to be escaped within double quotes, try replacing each one
> with \\
>
> 3) Why are you mixing \'s and /'s? Dunno whether it matters, but it's
> definitely better to stick to one or the other.
>
> 4) There is no 4!
>
> -Stut
>
> --
> http://stut.net/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

_________________________________________________________________
Use Messenger to talk to your IM friends, even those on Yahoo!
http://ideas.live.com/programpage.aspx?versionIdzdb59de-a857-45ba-81cc-685ee3e858fe
Paulo Sousa
Re: [PHP] How to Execute Exe File from PHP
October 21, 2008 06:35PM
Hi Alice

First, make sure about the value on $market and $length. Yeah, it's simple.

echo $market;
echo $length;
$a= shell_exec("./test.exe -m$market -d$length");
echo $a;

Second: "http://www.chipmunkninja.com/Program-Execution-in-PHP:[email protected]@";
A good explanation to use external commands (thanks chip!)

Third: give us more information: PHP version, OS. Maybe this time can be
useless, but important for future questions.

(sorry about my poor english)




2008/10/21 Alice Wei <[email protected]>

>
>
>
> Hi, Guys: Sorry about bothering everyone about this problem. It seems
> strange that now I try to create some arguments after what I tried to
> execute, it does not give me a thing.
> I get no error messages. No output file, and only a blank screen when I
> put the following snippet into the PHP file.
> $a= shell_exec("./test.exe -m$market -d$length");
> echo $a;
> What is odd is, I tired doing this by using a dos command prompt, it works
> entirely. Could anyone please give me a hint on what problem I am having
> now?
> Thanks for the heads up.
>
> Alice
> > CC: php-general@lists.php.net
> > From: stuttle@gmail.com
> > To: ajwei@alumni.iu.edu
> > Date: Mon, 20 Oct 2008 21:51:23 +0100
> > Subject: Re: [PHP] How to Execute Exe File from PHP
> >
> > On 20 Oct 2008, at 21:47, Alice Wei wrote:
> > > Has anyone tried to execute an .exe file from PHP? I am
> > > currently stuck in a situation where I cannot execute the script, and
> > > all I am getting is a blank screen.
> > >
> > > This is my code snippet used to execute the file:
> > >
> > > //execute program
> > > $a = @shell_exec("C:\Inetpub\wwwroot\test/test.exe");
> > > echo $a;
> > >
> > > The
> > > program above is supposed to generate a file, so I can read from it. I
> > > have previously set up a file, and I have no problems with reading the
> > > file.
> > > Can anyone please help me with the possible command to
> > > execute the script? I tried CURL too, but it does not seem to be
> > > working either.
> >
> > 1) Remove the @ before the function call, it's hiding the error message!
> >
> > 2) \ needs to be escaped within double quotes, try replacing each one
> > with \\
> >
> > 3) Why are you mixing \'s and /'s? Dunno whether it matters, but it's
> > definitely better to stick to one or the other.
> >
> > 4) There is no 4!
> >
> > -Stut
> >
> > --
> > http://stut.net/
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
> _________________________________________________________________
> Use Messenger to talk to your IM friends, even those on Yahoo!
>
> http://ideas.live.com/programpage.aspx?versionId=7adb59de-a857-45ba-81cc-685ee3e858fe
Alice Wei
RE: [PHP] How to Execute Exe File from PHP
October 22, 2008 04:20AM
HI,

To answer your questions, I run this on Windows. What is so weird is that when I do

$a= shell_exec("C:\Inetpub\wwwroot\/test.exe -m$market -d$length");
echo $a;

It works, and echoes everything as it is supposed to, and the file is also generated like I expected. However, the PHP file where I execute this from is in the same folder (which is why I thought using a . would work)

Could anyone please tell me if this is only way Ito do this on a Windows machine?

Thanks in advance, I think I am getting a little confused.

Alice



_________________________________________________________________
Search from any Web page with powerful protection. Get the FREE Windows Live Toolbar Today!
http://get.live.com/toolbar/overview
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Ian
RE: [PHP] How to Execute Exe File from PHP
October 22, 2008 11:55AM
On 22 Oct 2008 at 2:14, Alice Wei wrote:

>
> HI,
>
> To answer your questions, I run this on Windows. What is so weird is
> that when I do
>
> $a= shell_exec("C:\Inetpub\wwwroot\/test.exe -m$market -d$length"); echo
> $a;
>
> It works, and echoes everything as it is supposed to, and the file is also
> generated like I expected. However, the PHP file where I execute this from
> is in the same folder (which is why I thought using a . would work)
>
> Could anyone please tell me if this is only way Ito do this on a Windows
> machine?
>
> Thanks in advance, I think I am getting a little confused.

Hi,

It may help to run the command 'dir' to see where the web server considers its path to be:

<?
$a= shell_exec("dir");
echo $a;
?>

The response will include the current path as well as a directory listing.

Regards

Ian
--




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Sorry, only registered users may post in this forum.

Click here to login