Solved

Using exec in PHP to run program?

Posted on 2008-10-31
6
1,203 Views
Last Modified: 2013-12-13
Hello.

I'm trying to make use of the exec feature in PHP. I'm trying to run the following command:
C:\psshutdown.exe @c:\shutdown.txt -u administrator -p password -t 60 -f -k -c -m "This PC Will Blow Up In 60 Seconds!  Run You Fool!?"

The above command works prefectly in the command line, so i put together the code in the code snippet, although when i run it, it just 'thinks' for about 10 seconds then finishes, but the command isn't working. There is nothing output from '$output' and if i print '$return_var' it shows '-1073741502'.

i tried running a process manager to see what it was running and got these results:

http://img148.imageshack.us/my.php?image=ssinternalsuh7.jpg

It appears to show that it's run it, but it hasn't. I've noticed that it closed cmd very quickly after the command was run, perhaps not being it enough time to run?

Anyone have any suggestions why it's not working?

Thanks.

<?php

 

$output = array();

$return_var = 0;

 

 $command='C:\psshutdown.exe @c:\shutdown.txt -u administrator -p password -t 60 -f -k -c -m "This PC Will Blow Up In 60 Seconds!  Run You Fool!?"';

exec($command, $output, $return_var);

 

sleep(10);

 exec("exit(0)"); 

 

foreach($output as $outputline){

    echo("$outputline<br>");

}

 

?>

Open in new window

0
Comment
Question by:alumwell
  • 3
  • 3
6 Comments
 
LVL 16

Expert Comment

by:hankknight
ID: 22848595
To see the acual command-line error, you should add 2>&1 to the end of your command.

Also, you are sleeping for only 10 seconds, and I think you will need to sleep fore more than 60.


<?php

 

ignore_user_abort ();

set_time_limit (0);
 

$output = array();

$return_var = 0;

 

$command='C:\psshutdown.exe @c:\shutdown.txt -u administrator -p password -t 60 -f -k -c -m "This PC Will Blow Up In 60 Seconds!  Run You Fool!?"';

echo shell_exec($command . ' 2>&1');

 

sleep(70);

echo shell_exec("exit(0) 2>&1"); 

 

?>

Open in new window

0
 

Author Comment

by:alumwell
ID: 22848731
Thanks for your reply.

Just tried the code you gave me, unfortunatly it waits the time but the command isn't being run and it doesn't display anything once it's finished.

Any other ideas?

thanks again.
0
 
LVL 16

Expert Comment

by:hankknight
ID: 22849612
Does this give you an error you can read?
<?php
 

ignore_user_abort ();

set_time_limit (0);
 

$command='C:\psshutdown.exe @c:\shutdown.txt -u administrator -p password -t 60 -f -k -c -m "This PC Will Blow Up In 60 Seconds!  Run You Fool!?"';

echo shell_exec($command . ' 2>&1');
 

?>

Open in new window

0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:alumwell
ID: 22849834
Nope. Nothing. Any ideas?

Thanks.
0
 
LVL 16

Expert Comment

by:hankknight
ID: 22850408
I have only one more idea.

Create a batch file called "psshut.bat" and put it here:
C:\psshut.bat

The batch file should contain one line only:
C:\psshutdown.exe @c:\shutdown.txt -u administrator -p password -t 60 -f -k -c -m "This PC Will Blow Up In 60 Seconds!  Run You Fool!?"

Then exicute the batch file from PHP:

<?php
$command='C:\psshut.bat';
echo shell_exec($command . ' 2>&1');
?>

If that does not work, I cannot help.

What you are trying to do could be considered dangerous from a security standpoint.  It is possible that a firewall or some other security software is preventing you from doing this.  Beyond that, I am sorry, without a specific error message I am shooting in the dark.
0
 

Accepted Solution

by:
alumwell earned 0 total points
ID: 22850949
Thats now outputting:

C:\www\htdocs>C:\psshutdown.exe @C:\shutdown.txt -u administrator -p password -t 60 -f -k -c -m "This PC Will Blow Up In 60 Seconds! Run You Fool!?"
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now