Jump to content

Recommended Posts


  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)

 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.

; 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>


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))
    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


  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.



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

  • Similar Content

    • By Luigi
      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.
    • 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 .
    • By jacobestepp
      I am Very new to Autoit and I'm trying to figure out how to input text in an administrator Level Command prompt on windows 10. this is what I currently have
      Send ("#r") WinWaitActive("Run") Send("runas /user:Administrator cmd") Send("{Enter}") WinWait("C:\WINDOWS\system32\runas.exe") ControlClick("", "", "[CLASS:ConsoleWindowClass]") Send("test-Password") Send("{Enter}") The issue I am having is I can not send the "test-password" to the command prompt.  I cried adding the ControlClick command to place the cursor in he CMD box, but its still not working. What am I doing wrong?
  • Create New...