PHP - How to keep a Command Shell open for executing multiple commands? -
Hi, I'm trying to execute several commands using a PHP machine on a Windows machine. I tried this code:
& lt ;? Php $ output = shell_exec ("powershell.exe"); $ Output2 = shell_exec ("Writing Host Gokul"); Shell_exec ('departure'); Echo ('& lt; east & gt;'); Echo ($ output); Echo ($ output2); Echo ('& lt; / pre & gt;'); ? & Gt;
PHP executes each command with a new shell and closes when it is complete!
I think every 'shell_exec' creates a new shell and the control waits until command execution is complete. How can I turn it off until it opens in the background
Is not it sure whether 'proc_open' or 'popen' can help?
UPDATE When I use PROC_OPEN ()
$ descriptorspec = array (0 = & gt; array ("pipe", "r") , // stdin, a pipe that will be read from 1 => array ("pipe", "W"), // stadout is a pipe that has a child 2 => array ("file", "error.Txt" , "A") // stderr is a file to write); $ Process = proc_open ('cmd.exe', $ descriptorspec, $ pipe); If (is_resource ($ process)) {FILIT ($ PIPE [0], 'DIR'); Filitt ($ pipe [0], 'power shale .exe'); Filitt ($ pipe [0], 'write-host gokul'); Fclose ($ pipe [0]); Echo stream_get_contents ($ pipe [1]); Fclose ($ pipe [1]); Proc_close ($ process); }
It prints the prompt only. Can I really use proc_open to execute multiple commands? If so, then?
Microsoft Windows [version 6.1.7601] Copyright (c) 200 Microsoft Corporation. All rights reserved. C: \ WAMP \ Bin \ Apache \ Apache2.2.17 & gt; more? Using
proc_open
is the right attempt but you need it Finish every command with the character of a new line as if you manually type the command in the shell session.
It should look like this:
fwrite ($ pipes [0], 'dir'. PHP_EOL); FILIT ($ Pipe [0], 'PowerShel.XA'. PHP_EOL); FILIT ($ pip [0], 'write-host Gokul'. PHP_EOL);
Comments
Post a Comment