vForums Support > Programming & Coding :: Programming Discussion :: > Small Code Help

Small Code Help - Posted By dog199200 (dog199200) on 30th Jan 10 at 6:06am
Hello,

I have a small script that I need a bit of help with. What it is suppose to do it check to see if a program is running and if the program is running it echo's back Online, but if the program is not running it echo's back Offline, but the problem is that it always and I mean always echo's back thats its online, even when the program isn't running, so can someone please fix this code for me? I would say it can be done in batch if needed but the problem is that I have to use almost the same exact thing in another file that requires it to be in php.

Code:
 
  1. <?php
  2. $command = shell_exec('TASKLIST /FI "imagename eq Server.exe"');
  3.  
  4. if ($command) {
  5.  
  6. echo '<FONT COLOR=#00DD00><B>ONLINE</B></FONT>';
  7.  
  8. } else {
  9.  
  10. echo '<FONT COLOR=#DD0000><B>OFFLINE</B></FONT>';
  11.  
  12. }
  13. ?>
 


Re: Small Code Help - Posted By Ross (admin) on 30th Jan 10 at 11:01am
Write out what the value of "$command" is to find out what it says if the program is not running.

if($command) doesn't check what the value of $command is, it just checks that it has a value.

Re: Small Code Help - Posted By dog199200 (dog199200) on 30th Jan 10 at 11:26am
Edit: Nvm I found a work around using a batch File