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 :/

1 Answer 1

2

I guess the mysterious symbol is a regular newline character. Try using trim() instead;

Sign up to request clarification or add additional context in comments.

2 Comments

omg u saved my life, trim function worked! thank u so much! but now can u tellme how can that be possible? where was the last character? :s
Its an invisible control character for breaking the text to a new line. linefeed (LF or 0x0A (10) in ASCII) or maybe carriage return (CR or 0x0D (13) in ASCII)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.