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

  • Similar Content

    • 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
       
       
       
       
    • 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?
    • By boomingranny
      Use this UDF to add a console gui to your script (with log file):
      It uses the Hidden Autoit window (that you probably didn't even know existed)
      Closing Console window will terminate script.
      example of console:

      #include-once #include <GuiEdit.au3> EnableConsoleGui("example.log") ;example: ;------------------------ ConsoleWrite ("Hello World") For $i = 1 To 10 ConsoleWrite (".") Sleep(200) Next ConsoleWrite ("done") ConsoleWrite(@CRLF) ConsoleWrite ("close me to exit"&@CRLF) While 1 Sleep(1000) WEnd ;------------------------ ;end of example code Func EnableConsoleGui($Logfile="") ;EnableConsoleGUI ;by Daniel Barnes 20/04/2018 ;Uses AutoIt's Hidden window as a console (output only) Global $pidChild ;if we don't have a parent (as the parent window would have our script name) If Not WinExists(StringTrimRight(@ScriptName,4)) Then Opt("TrayIconHide",1) ;get Autoit's hidden window handle local $hWnd = WinGetHandle(AutoItWinGetTitle()) ;move the autoit hidden window to the middle of the screen WinMove($hWnd, "", (@DesktopWidth / 2) - 250, (@DesktopHeight / 2) - 250, 500, 500) ;get the Handle of the edit box in Autoit's hidden window $hEditBox = ControlGetHandle($hWnd,"","[CLASS:Edit; INSTANCE:1]") ;show it WinSetState($hWnd, "", @SW_SHOW) ;set its title = our script name WinSetTitle($hWnd,"",StringTrimRight(@ScriptName,4)) ;Spawn a child "copy" of the script, enabling reading of its console... If @Compiled Then ;2 = $STDOUT_CHILD. This avoids requiring the AutoItConstants.au3 in this sample code $pidChild= Run( FileGetShortName(@ScriptFullPath),@ScriptDir,"",2) Else ;2 = $STDOUT_CHILD. This avoids requiring the AutoItConstants.au3 in this sample code $pidChild= Run( FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath),@ScriptDir,"",2) EndIf OnAutoItExitRegister("EnableConsoleGui_CloseChildPID") ;read the console, while the child window exists (and the console window is visible) While ProcessExists($pidChild) $ConsoleRead = StdoutRead($pidChild) If $ConsoleRead then $text = StringLeft(ControlGetText($hWnd,"",$hEditBox),65535) If $Logfile Then FileWrite($Logfile,$ConsoleRead) $text &= $ConsoleRead ControlSetText($hWnd,"",$hEditBox,$text) ConsoleWrite($ConsoleRead) ;scroll to bottom of console edit window _GUICtrlEdit_SetSel($hEditBox, 65535, 65535) endif Sleep(250) WEnd exit endif EndFunc Func EnableConsoleGui_CloseChildPID() ;if this func isn't used ;when you close the console gui ;the child "clone" of your script will keep running ProcessClose($pidChild) EndFunc
×
×
  • Create New...