1

Well guys i dont really know how to start, is the first time that i work with powershell and PHP together, but now i dont know how to deal with this problem, therefore im here..

Im developing a webinterface for a company to administrate services (turn on/off servers basically). I have already programmed the powershells scripts, everything run fine 0 problems.

But i have a part where i try to show in a AlertBox(javascript) the status of a process (the powershell script has already given me the return value but i cant understand why php dont process it like a string or text.

Check it Out a piece of my code :

    <?php
               if (isset($_POST['button']))
          {
        $service = $_POST["service1"];
        $psPath = "powershell.exe";
        $psDIR = "C:\\xampp\\htdocs\\shell\\";
        $psScript = "check-status.ps1";
        $runScript = $psDIR. $psScript;
        $runcheck = $psPath." ".$runScript." 2>&1"; 
        $computername = "xen-80-42";

        $go = shell_exec("$runcheck -passwd 'Hpdprqn5' -user 'Administrator' -computer '$computername' -service '$service' < NUL");



echo "<script type='text/javascript'>alert('" . $service . " is currently " . $go . " on " . $computername . "'); </script>"; 

         }
    ?>

    <form method="post">
        <p>
            <input type="text" name="service1" id="service1" maxlength="20"></input> <button name="button">Check Status</button>
        </p>
        </form>

Well

Everything works fine, the script give back 2 possible values : "Running" or "Stopped" that means , the value of the variable $go, should be or "Running" or "Stopped"

Ok i tried with a process that is already running, therefore : echo $go; print "Running"

i thought was a problem because maybe the returned value $go is not String. But i solved that using gettype($go) , and the variable is STRING!

but can somebody explain me why when i wanna count the characters of that String, using strlen($go) , i get a return of 8 characters? RUNNING has only 7 Letters, not 8

for that reason i cant execute the ALERT in Javascript (code above), because java doesnt take it as a String or something like that

something is wrong there i think, btw when i tried to make a comparation like that:

if ($go == "Running") { echo "Everything ok"; } else { echo "different values";}

i get the second options, both values are not really equal, they are diferent. but wheree? i cant see anything..

I hope someone can helpme cause im frustrate :(

btw i tried :

strval($go);
(string)$go;
$var = "$go";

NOTHING WORKS :(

if its necesary ask for the powershell script, but i think its not necesary you see that php receives the value as STRING :/

4

1 回答 1

2

我猜这个神秘的符号是一个常规的换行符。尝试使用 trim() 代替;

于 2013-04-26T13:45:58.593 回答