Jump to content

Recommended Posts

Greetings,

  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.

Share this post


Link to post
Share on other sites
$sFilePath = "C:\gstreamer\1.0\x86_64\bin\"

Local $iPID = Run($sFilePath & "gst-launch-1.0 videotestsrc ! autovideosink" , $sFilePath, @SW_HIDE, $STDOUT_CHILD)

; Wait until the process has closed using the PID returned by Run.
ProcessWaitClose($iPID)

; Read the Stdout stream of the PID returned by Run.
Local $sOutput = StdoutRead($iPID)

This would be the way to run apps from the command line...

Share this post


Link to post
Share on other sites

You can also combine commands with cmd using & or &&, example:

#include <AutoItConstants.au3>

Example()

Func Example()
    Local $iPID = Run(@ComSpec & ' /C CD "C:\gstreamer\1.0\x86_64\bin"&&gst-launch-1.0 videotestsrc ! autovideosink', "", @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD))
    ProcessWaitClose($iPID)
    Local $sOutput = StdoutRead($iPID)
        If StringStripWS($sOutput, 8) <> "" Then ConsoleWrite("##### StdOut #####" & @CRLF & $sOutput & @CRLF)
    Local $sStdErr = StderrRead($iPID)
        If StringStripWS($sStdErr, 8) <> "" Then ConsoleWrite("##### StdErr #####" & @CRLF & $sStdErr & @CRLF)
EndFunc   ;==>Example

 

Share this post


Link to post
Share on other sites

Greetings,

  Thank you for the replies, much appreciated.

  @Nine why does your "Run" command not reference/call any command to open the console window?  I mean how does AutoIT know the stated command you wrote is to be executed in the console?

  @Subz would I also be able to write the command alternatively as indicated in the documentation...using Run(@ComSpec & " /c " & 'commandName', "", @SW_HIDE)   ...therefore it would read:

  Run(@ComSpec & " /c" & 'C:\gstreamer\1.0\x86_64\bin & gst-launch-1.0 videotestsrc ! autovideosink', "", @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD))   ....?  does the "&" provide an attached 'second line' to be executed following the command before the "&" ('C:\gstreamer\1.0\x86_64\bin')...?

  Are the "STDERR_CHILD" and "STDOUT_CHILD" just regular strings?  Therefore I could examine them with "StringInStr" for keywords such as "prerolling" or "error"...OR do I need to accomplish that using the "StderrRead" and "StdoutRead" which will produce the readable string(s)...?

  Thanks again for the responses and sorry for my additional questions...I'm just trying to wrap my head around this.

Regards

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Chimp
      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
      thanks
      #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  
    • By Luigi
      Greetings,
      I need write a command line to run an .exe with parameters, one this parameters is a password with special characters  like:   [ ] \ "  etc.
      The password is write between double cotes too.
      When run this command line, catch error.
      I buid this function, sometimes run ok, others show error.

      Someone can any idea?

      Best ragards
      #include <Array.au3> Global $G_AIX_DEFAULT_PASSWORD = "******" Func Scape_Word_To_MSDOS($var = "") ;~ https://www.robvanderwoude.com/escapechars.php Local $aCharacters[][2] = [ _ ["%", "%%"], _ ["^", "^^"], _ ["&", "^&"], _ ["<", "^<"], _ [">", "^>"], _ ["|", "^|"], _ ["'", "^'"], _ ["`", "^`"], _ [",", "^,"], _ [";", "^;"], _ ["=", "^="], _ ["(", "^("], _ [")", "^)"], _ ["!", "^^!"], _ ["\", "\\"], _ ["[", "\["], _ ["]", "\]"], _ ['"', '\"""'], _ [".", "\."], _ ["*", "\*"], _ ["?", "\?"] _ ] Local $iSearch $var = StringSplit($var, "", $STR_NOCOUNT) Local $iSize = UBound($var, $UBOUND_ROWS) - 1 For $ii = 0 To $iSize $iSearch = _ArraySearch($aCharacters, $var[$ii]) If $iSearch >= 0 Then $var[$ii] = $aCharacters[$iSearch][1] Next Return _ArrayToString($var, "") EndFunc ;==>Scape_Word_To_MSDOS Local $password = "-Dk5iFB2UjOt[-x|""" & "" Local $password_scape = Scape_Word_To_MSDOS($password) ConsoleWrite("[" & $password & "]" & @LF) ConsoleWrite("[" & $password_scape & "]" & @LF)  
       
    • By pctechtv
      I use a program called Screenpresso. It can run a command that captures the screen from certain coordinates. I would like to be able to capture the mouse coordinates and then fill them in my command. The normal command looks like this.
      screenpresso.exe -captureregion "D:\Test\test2.jpg" 0;0;1280;720 It is at 0;0 where I would like to insert the mouse coordinates. Can someone show me how to do this with AutoIt Thanks
    • By Jeep
      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.
      JPD_Simply.au3
      JPD_Simply_Demo.au3
    • By MadhaN
      Hi all,
      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 .
      srno,name,ip,pass
      1,name1,ip1,pass1
      2,name2,ip2,pass2
       
       
       
       
×
×
  • Create New...