Jump to content

Need to Display DOS Command Line Output in the GUI


 Share

Recommended Posts

i currently trying to make a GUI for 2 command line programs FLVTOOLS.exe and FLVMDI.exe...

But i am at the point in my GUI where i need to RUN the the COMMAND LINES and add the SWITCHES. I am getting confused as I searched and found some examples but they were for older versions of AUTOIT

I have many check boxes that the user can select either YES/NO that will use the switches for examples FLVMDI.eve depending if the user selected it.

Using the RUN or RUNWAIT the COMMAND Window pops up and disappears so i can not see what gets processed or verify it did properly??

RunWait(@ComSpec & " /c " & 'flvmdi.exe' & $commandline, "", @SW_MAXIMIZE)

this where i am getting confused on these flags for the RUN command but i think it holds the solution for me..

[optional] Provide a meaningful handle to one or more STD I/O streams of the child process.

1 ($STDIN_CHILD) = Provide a handle to the child's STDIN stream

2 ($STDOUT_CHILD) = Provide a handle to the child's STDOUT stream

4 ($STDERR_CHILD) = Provide a handle to the child's STDERR stream

8 ($STDERR_MERGED) = Provides the same handle for STDOUT and STDERR. Implies both $STDOUT_CHILD and $STDERR_CHILD.

any help or example of code snippet appreciated

rick

Link to comment
Share on other sites

i currently trying to make a GUI for 2 command line programs FLVTOOLS.exe and FLVMDI.exe...

But i am at the point in my GUI where i need to RUN the the COMMAND LINES and add the SWITCHES. I am getting confused as I searched and found some examples but they were for older versions of AUTOIT

I have many check boxes that the user can select either YES/NO that will use the switches for examples FLVMDI.eve depending if the user selected it.

Using the RUN or RUNWAIT the COMMAND Window pops up and disappears so i can not see what gets processed or verify it did properly??

RunWait(@ComSpec & " /c " & 'flvmdi.exe' & $commandline, "", @SW_MAXIMIZE)

this where i am getting confused on these flags for the RUN command but i think it holds the solution for me..

[optional] Provide a meaningful handle to one or more STD I/O streams of the child process.

1 ($STDIN_CHILD) = Provide a handle to the child's STDIN stream

2 ($STDOUT_CHILD) = Provide a handle to the child's STDOUT stream

4 ($STDERR_CHILD) = Provide a handle to the child's STDERR stream

8 ($STDERR_MERGED) = Provides the same handle for STDOUT and STDERR. Implies both $STDOUT_CHILD and $STDERR_CHILD.

any help or example of code snippet appreciated

rick

Instead of running the program with Run or RunWait I would open up a command prompt, then send the commands to that. You will then be able to see the results as you want.

$cmdPID = Run("cmd", "", @SW_SHOWNORMAL)
WinWaitActive("cmd.exe")
$hDos = WingetHandle("cmd.exe")
..

.
;when you want to run your program this line is useful
SendKeepActive($hDos)

;then send the command
Send('flvmdi.exe ' & $commandline)
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

i tried adding the snippet above as you can see in the my script below but having a problem.. CMD.EXE window pops up but it hangs on i think on the WinWaitActive("cmd.exe") as it opens the DOS WINDOW but does not send any command to it..

if I comment out the WinWaitActive("cmd.exe") then it sends a command but it cuts of the first character of what i am sending??

lvmdi.exe

instead of the

flvmdi.exe

any help thanks

CODE
#cs ----------------------------------------------------------------------------

AutoIt Version: 3.2.12.1

Author: myName

Script Function:

Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()

#cs

Local $defaultstatus = "Ready", $status, $filemenu, $fileitem

Local $helpmenu, $saveitem, $infoitem, $exititem, $recentfilesmenu

Local $separator1, $viewmenu, $viewstatusitem, $okbutton, $cancelbutton

Local $statuslabel, $msg

#ce

Local $tab, $tab0, $tab0but_inputfile, $tab0but_inputfilepath, $tab0but_outputfile, $tab0but_outputfilepath

Local $tab1, $flvfolder, $tab1but_inputfolder, $tab1but_inputfolderpath, $tab1but_outputfolder, $tab1but_outputfolderpath

Local $tab2, $tab2OK, $msg

Local $flvfile, $message, $flvfileselected

Local $addkeyframe, $addlastsecond

Local $var, $button_process_files, $answer, $commandline, $cmdPID, $hDos

GUICreate("Flvtool2 GUI - FLV MetaData Injector", 400, 400) ; will create a dialog box that when displayed is centered

$tab = GUICtrlCreateTab(10, 10, 380, 115)

; FIRST TAB FLV FILE INPUT

$tab0 = GUICtrlCreateTabItem("Single File"); will display Tab Text

GUICtrlSetState(-1, $GUI_SHOW) ; will be display first

GUICtrlCreateLabel("Input FLV File:", 20, 40, 300, 20)

$tab0but_inputfile = GUICtrlCreateButton("...", 365, 55, 20, 20)

$tab0but_inputfilepath = GUICtrlCreateInput($flvfile, 20, 55, 340, 18)

GUICtrlCreateLabel("Output FLV File:", 20, 80, 300, 20)

$tab0but_outputfile = GUICtrlCreateButton("...", 365, 95, 20, 20)

$tab0but_outputfilepath = GUICtrlCreateInput($flvfile, 20, 95, 340, 18)

; SECOND TAB FLV FOLDER INPUT

$tab1 = GUICtrlCreateTabItem("All Files In A Folder"); will display Tab Text

GUICtrlCreateLabel("Input FLV File Folder:", 20, 40, 300, 20)

$tab1but_inputfolder = GUICtrlCreateButton("...", 365, 55, 20, 20)

$tab1but_inputfolderpath = GUICtrlCreateInput($flvfolder, 20, 55, 340, 18)

GUICtrlCreateLabel("Output FLV File Folder:", 20, 80, 300, 20)

$tab1but_outputfolder = GUICtrlCreateButton("...", 365, 95, 20, 20)

$tab1but_outputfolderpath = GUICtrlCreateInput($flvfolder, 20, 95, 340, 18)

GUICtrlCreateTabItem("") ; end tabitem definition

GUICtrlCreateLabel("MetaData Options:", 10, 135, 300, 20)

$addkeyframe = GUICtrlCreateCheckbox ("Add Keyframes Object", 10, 150, 360, 20)

GUICtrlSetState($addkeyframe, $GUI_CHECKED)

$addlastsecond = GUICtrlCreateCheckbox ("Injects onLastSecond Event", 10, 170, 360, 20)

GUICtrlSetState($addlastsecond, $GUI_CHECKED)

$button_process_files = GUICtrlCreateButton("Inject MetaData", 290, 370, 100, 20)

GUISetState()

; Run the GUI until the dialog is closed

While 1

$msg = GUIGetMsg()

If $msg = $tab0but_inputfile Then ; Dialong To Select the Input File

$message = "Select A Video File"

$flvfile= FileOpenDialog($message, @WorkingDir & "\", "Videos (*.flv)", 1 )

If @error Then

;MsgBox(4096,"","No File chosen")

Else

GUICtrlSetData ($tab0but_inputfilepath, $flvfile)

GUICtrlSetData ($tab0but_outputfilepath, $flvfile)

EndIf

EndIf

If $msg = $tab0but_outputfile Then ; Dialong to Select the Output File

$message = "Save Video File As"

$flvfile= FileOpenDialog($message, @WorkingDir & "\", "Videos (*.flv)", 1 )

If @error Then

;MsgBox(4096,"","No File chosen")

Else

GUICtrlSetData ($tab0but_outputfilepath, $flvfile)

EndIf

EndIf

If $msg = $tab1but_inputfolder Then ; Dialong To Select the Input Folder

$message = "Select Input Folder"

$flvfolder= FileSelectFolder($message, "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 2 + 8)

If @error Then

MsgBox(4096,"","No Folder chosen")

Else

GUICtrlSetData ($tab1but_inputfolderpath, $flvfolder)

GUICtrlSetData ($tab1but_outputfolderpath, $flvfolder)

EndIf

EndIf

If $msg = $button_process_files Then

;$var = GUICtrlRead ($addkeyframe)

If FileExists(GUICtrlRead ($tab0but_inputfilepath)) Then

$answer=MsgBox(4+32+4096, "Inject MetaData", "Do You Want To Inject the MetaData Now!")

If $answer = 6 Then

$var = GUICtrlRead ($addkeyframe)

$commandline = '\H'

;MsgBox(4096, "YES", $commandline)

$cmdPID = Run("cmd", "", @SW_SHOWNORMAL)

WinWaitActive("cmd.exe")

$hDos = WingetHandle("cmd.exe")

;when you want to run your program this line is useful

SendKeepActive($hDos)

;then send the command

Send("flvmdi.exe")

;RunWait(@ComSpec & " /c " & 'flvmdi.exe' & $commandline, "", @SW_HIDE)

;Run(@ComSpec & " /c " & 'flvmdi.exe', "", @SW_HIDE)

ElseIf $answer = 7 Then

MsgBox(4096, "NO", "Exit")

EndIf

Else

MsgBox(4096,"File Does Not Exist", "Please Enter Complete Filename and Path")

EndIf

;MsgBox(0, "KEYFRAME", GUICtrlRead ($tab0but_outputfilepath))

;MsgBox(0, "KEYFRAME", GUICtrlRead ($addkeyframe))

;MsgBox(0, "lastseond", GUICtrlRead ($addlastsecond))

EndIf

If $msg = $GUI_EVENT_CLOSE Then ExitLoop

WEnd

EndFunc ;==>Example

Link to comment
Share on other sites

also i searching try to find examples and found a couple of things that seemed similar but the scripts were from 2 years ago.. and they do not seem to work with the new version of autoit i am using??

CODE
#include <GUIConstants.au3>

#include "constants.au3"

local $gui, $edit, $ping, $lineout, $WS_VSCROLL, $WS_HSCROLL, $ES_READONLY

$gui = GUICreate("console stuff")

$edit = GUICtrlCreateEdit("", 10, 10, 300, 300, BitOr($WS_VSCROLL, $WS_HSCROLL,$ES_READONLY))

GUISetState()

$ping = Run(@ComSpec & " /c ping google.com", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

While 1

$lineout = StdoutRead($ping)

If @Error = -1 Then ExitLoop

GUICtrlSetData($edit, $lineout & @CRLF, 1)

WEnd

While 1

$get = GUIGetMsg()

If $get = -3 Then Exit

WEnd

Link to comment
Share on other sites

this might seem like a backward way of doing things, but perhaps you can dump the result of your DOS command into a text file, then use filereadline() to check it was a success?

to dump the result of a dos command into a file, you just finish the command with "> filename". For example:

ping www.google.com > result.txt

I've only ever done this with ping tests, but I -think- it works for all dos commands.

Link to comment
Share on other sites

this might seem like a backward way of doing things, but perhaps you can dump the result of your DOS command into a text file, then use filereadline() to check it was a success?

to dump the result of a dos command into a file, you just finish the command with "> filename". For example:

ping www.google.com > result.txt

I've only ever done this with ping tests, but I -think- it works for all dos commands.

ok i will give it a shot as this is pissing me off... just trying to get the SEND command to send some text to the window but it cuts off the first letter..

i am using WINDOWS VISTA and do not know if thats as issue..

here is a simple test and it shows ick and command prompt instead of rick

CODE
Example()

Func Example()

local $var

$var = "rick"

Run(@COMSPEC & " /k Dir C:\")

WinActive("cmd.exe", 1)

Send ($var,1)

EndFunc ;==>Exampler

Link to comment
Share on other sites

Add a Sleep(300) between WinActive and Send - I'm sure it needs a little time for that window to become active.

Another way is to use SendKeepActive instead of Send (after the same Sleep command).

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

i tried adding the snippet above as you can see in the my script below but having a problem.. CMD.EXE window pops up but it hangs on i think on the WinWaitActive("cmd.exe") as it opens the DOS WINDOW but does not send any command to it..

if I comment out the WinWaitActive("cmd.exe") then it sends a command but it cuts of the first character of what i am sending??

lvmdi.exe

instead of the

flvmdi.exe

any help thanks

Adfd this line to the top of your script, then it will work (I hope).

Opt("WinTitleMatchMode",2);then the WInWaitActive won't hang and you won't get a missing letter.

Otherwise you need to put the complete title in, say "C:\Windows\Ststem32\cmd.exe".

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Adfd this line to the top of your script, then it will work (I hope).

Opt("WinTitleMatchMode",2);then the WInWaitActive won't hang and you won't get a missing letter.

Otherwise you need to put the complete title in, say "C:\Windows\Ststem32\cmd.exe".

yeah i am still losing the first letter or two..

but if I use complete path like you showed it works?

C:\Windows\Ststem32\cmd.exe

Link to comment
Share on other sites

Adfd this line to the top of your script, then it will work (I hope).

Opt("WinTitleMatchMode",2);then the WInWaitActive won't hang and you won't get a missing letter.

Otherwise you need to put the complete title in, say "C:\Windows\Ststem32\cmd.exe".

thanks as i got it to work with your example... somehow or somewhere there was a , 1 added after the WinWaitActive in my script.. anyways once i removed that and added your the WinTitleMatchMode it fixed the problem..

thanks..

CODE
Opt("WinTitleMatchMode",2);

Example()

Func Example()

local $var, $comspec

$var = "rick"

$comspec = @COMSPEC

Run($comspec & " /k" & "Dir C:\")

WinWaitActive("cmd")

Send ($var,1)

EndFunc ;==>Example

Edited by subfighter
Link to comment
Share on other sites

i got it to work.

That's good. Well done.

thanks..

NP :P

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...