Solved

Using exec in PHP to run program?

Posted on 2008-10-31
6
1,205 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

786 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