Recently Browsing 0 members
No registered users viewing this page.
I'm trying to drive a command prompt by sending instructions via a NamedPipe.
This way you can (should) be able to send commands to the command prompt and at the same time "view" the result in the same window.
This is not allowed if you run a command prompt with "opt_flag" parameters (redirected streams) because this will disable StdOut on the cmd itself.
This small (trivial) snippet works for the first command sent to the cmd, but further submissions will fail.
Maybe the problem is in how I use the run () command to start a new cmd with the StdIn redirect from the NamedPipe. It seems that the generated cmd will close automatically after the first reception of the command via NamedPipe.
suggestions on how to make it work are welcome
#include <NamedPipes.au3> #include <WinAPI.au3> ; Creates an instance of a named pipe Global $sPipeName = "\\.\pipe\pipename" Global $hPipe = _NamedPipes_CreateNamedPipe($sPipeName, 1, 1) MsgBox(0, "Debug", "Pipe created. Now open a CMD") ; run a cmd with only StdIn redirected (StdIn data incoming from a pipe) Global $hCMD = Run(@ComSpec & " /K cmd < " & $sPipeName & @CRLF, "c:\") ; ok? MsgBox(0, "Debug", "now Send a command to the cmd via a NamedPipe") _StdInPipeWrite("dir" & @CRLF) MsgBox(0, 'Debug', "further commands will fail" & @CRLF & "now send command 'dir c:\windows'") $sMessage = "Dir c:\windows" & @CRLF _StdInPipeWrite($sMessage) MsgBox(0, 'Debug', "send another command (will also fail)" & @CRLF & "now send command 'echo Hello'") _StdInPipeWrite("echo Hello" & @CRLF) MsgBox(0, "Debug", "end of test") ProcessClose($hCMD) Func _StdInPipeWrite($sMessage) ; =============================================================================================================================== ; This function writes a message to the pipe ; =============================================================================================================================== Local $iWritten, $iBuffer, $pBuffer, $tBuffer $iBuffer = StringLen($sMessage) + 1 $tBuffer = DllStructCreate("char Text[" & $iBuffer & "]") $pBuffer = DllStructGetPtr($tBuffer) DllStructSetData($tBuffer, "Text", $sMessage) If Not _WinAPI_WriteFile( _ $hPipe, _ ; ...... Handle to the file to be written $pBuffer, _ ; .... Pointer to the buffer containing the data to be written $iBuffer, _ ; .... Number of bytes to be written to the file $iWritten, _ ; ... The number of bytes written 0 _ ; ............ [optional] A $tagOVERLAPPED structure or a pointer to it ) Then ConsoleWrite("WriteMsg: _WinAPI_WriteFile failed" & @CRLF & _WinAPI_GetLastErrorMessage()) Else ConsoleWrite("WriteMsg: write OK" & @CRLF & _WinAPI_GetLastErrorMessage() & @CRLF) EndIf EndFunc ;==>_StdInPipeWrite
I would like to be able to write a script to send commands to the console for creation of Gstreamer pipelines. I was thinking of something similar to this:
Local $iPID = Run("C:\Windows\System32\cmd", "", @SW_MAXIMIZE) ;THIS OPENS THE CONSOLE...!!! if $iPID == 0 Then ConsoleWrite(@CRLF & "I DID NOT OPEN CMD...error: " & @error & @CRLF) if $iPID <> 0 Then ConsoleWrite(@CRLF & "I OPENED CMD...!!!" & @CRLF) $hCmd = WinGetHandle("C:\WINDOWS\system32\cmd.exe") if $hCmd <> 0 Then WinActivate($hCmd) ;ensure command console is active... $sOutput = Send("cd C:\gstreamer\1.0\x86_64\bin" & @CRLF, $SEND_RAW) $sOutput = Send("gst-launch-1.0 videotestsrc ! autovideosink" & @CRLF, $SEND_RAW) Sleep(3000) ControlSend($hCmd, "", "", "exit" & @CR) EndIf ;$hCmd NOT "0"... I don't really know if this is the best way to open the console and send commands into it. I'm also not sure about how to best catch any errors that may occur...likely this needs to be accomplished with the STDOUTREAD command however I've not had experience using it before and therefore would appreciate some advice that anybody may offer.
Basically I'm seeking guidance on how to best automate the opening of the console, sending lines of commands to be executed, and handling any potential errors in the execution of those commands...I thank you in advance. Regards.
Here is a small library (UDF) that I use all the time. Not transcendent, it’s just to simplify my life.
When I use the ConsoleWrite function, more than 99.99 percent, I go to the line (Newline), more than 99.99 %, parameters à the same except information that i exam. _CW is born.
The second one _CW_Fmt allows to display marks (Fmt for Formatting) and allows to evaluate the format the length of a variable and the position of some characters without counting too much :-).
For the functions derived from MsgBox () again the same observation, always the same parameters following the context: Info, Error or Warning. Thus were born _MB_Info, _MB_Error and _MB_Warning.
As for _MB_IsOk, the same observation about the logical answer we are interested in a question with two choices: agree or disagree and not much else (True or False).
All your remarks, suggestions and constructive criticism are welcome.
Script to get input from user ,check in csv file and read corresponding values and pass that value to cmdBy MadhaN
I have a csv file as below, I wand to find srno from csv and send corresponding ip and pass to commend cmd prompt.
Please guide me to create script .