Solved

Using exec in PHP to run program?

Posted on 2008-10-31
6
1,213 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

705 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