Jump to content

How to capture multiline output from DOS


 Share

Recommended Posts

Anyone can give me a reference how to capture output from DOS to edit box?

I try this one but it returns only one line in the edit box

#include <GUIConstants.au3>
#include <Constants.au3>
#include <process.au3>

Dim $run[4]
Dim $a,$b,$c,$foo,$line,$test

$frmLog = GUICreate("Elkie Backup Logger", 474, 285, 193, 115)
$cmdCollect = GUICtrlCreateButton("(Not allowed)", 385, 20, 81, 41, $BS_ICON)
GUICtrlSetImage($cmdCollect, "C:\Downloads\web\iconsext\icons\icardres_302.ico")
$edit1 = GUICtrlCreateEdit("", 22, 21, 354, 243)
GUICtrlSetData(-1, "edit1")
$cmdCancel = GUICtrlCreateButton("(Not allowed)", 385, 69, 81, 41, $BS_ICON)
GUICtrlSetImage($cmdCancel, "C:\Downloads\web\iconsext\icons\icardres_304.ico")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cmdCollect
            CompileMe()
        Case $cmdCancel
            exit
    EndSwitch
WEnd

Func CompileMe()
$foo = run(@comspec & " /c dir \\hppmapp01\d$\Backup_POrder\*","",@SW_SHOW,$STDERR_CHILD + $STDOUT_CHILD)
$line=StdoutRead($foo)
$test = $line
GUICtrlSetData($edit1,$test)
;MsgBox(0,"",$test)
EndFunc

then i try to modify it after i take a look at some reference, but the script stops(loop/halted):

#include <GUIConstants.au3>
#include <Constants.au3>
#include <process.au3>

Dim $run[4]
Dim $a,$b,$c,$foo,$line,$test

$frmLog = GUICreate("Elkie Backup Logger", 474, 285, 193, 115)
$cmdCollect = GUICtrlCreateButton("(Not allowed)", 385, 20, 81, 41, $BS_ICON)
GUICtrlSetImage($cmdCollect, "C:\Downloads\web\iconsext\icons\icardres_302.ico")
$edit1 = GUICtrlCreateEdit("", 22, 21, 354, 243)
GUICtrlSetData(-1, "edit1")
$cmdCancel = GUICtrlCreateButton("(Not allowed)", 385, 69, 81, 41, $BS_ICON)
GUICtrlSetImage($cmdCancel, "C:\Downloads\web\iconsext\icons\icardres_304.ico")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cmdCollect
            CompileMe()
        Case $cmdCancel
            exit
    EndSwitch
WEnd

Func CompileMe()
$foo = run(@comspec & " /c dir \\hppmapp01\d$\Backup_POrder\*","",@SW_SHOW,$STDERR_CHILD + $STDOUT_CHILD)
while 1
$line=StdoutRead($foo)
If @error = -1 then ExitLoop
$test = $line
WEnd
GUICtrlSetData($edit1,$test)
;MsgBox(0,"",$test)
EndFunc

Enlight me please!

Edited by Elkie
Link to comment
Share on other sites

You need to concatenate each line with the previous stored value, so do it with &= (same as $var = $var & 'new string')

Global $text, $foo = Run(@Comspec & " /c dir \\hppmapp01\d$\Backup_POrder\*", "", @SW_SHOW, $STDOUT_CHILD)
Do
    $text &= StdOutRead($foo)
Until @error

:shocked:

It's not working, the edit box just blanks shows nothing? :(

#include <GUIConstants.au3>
#include <Constants.au3>
#include <process.au3>

Dim $run[4]
Dim $a,$b,$c,$foo,$line,$test

$frmLog = GUICreate("Elkie Backup Logger", 474, 285, 193, 115)
$cmdCollect = GUICtrlCreateButton("(Not allowed)", 385, 20, 81, 41, $BS_ICON)
GUICtrlSetImage($cmdCollect, "C:\Downloads\web\iconsext\icons\icardres_302.ico")
$edit1 = GUICtrlCreateEdit("", 22, 21, 354, 243)
GUICtrlSetData(-1, "edit1")
$cmdCancel = GUICtrlCreateButton("(Not allowed)", 385, 69, 81, 41, $BS_ICON)
GUICtrlSetImage($cmdCancel, "C:\Downloads\web\iconsext\icons\icardres_304.ico")
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cmdCollect
            CompileMe()
        Case $cmdCancel
            exit
    EndSwitch
WEnd

Func CompileMe()
$foo = run(@comspec & " /c dir \\hppmapp01\d$\Backup_POrder\*.bak","",@SW_SHOW,$STDERR_CHILD + $STDOUT_CHILD)

Do
$line&=StdoutRead($foo)
until @error

GUICtrlSetData($edit1,$test)
EndFunc
Link to comment
Share on other sites

Try declaring $line before you use it before the Do loop as I did with $text.

Edit:

Just seen you use it globally......hmm

GUICtrlSetData($edit1,$test)

; should be...

GUICtrlSetData($edit1, $line)

:shocked:

Edited by MHz
Link to comment
Share on other sites

Try this:

Opt('TrayIconDebug',1)

Func CompileMe()
    $foo = Run(@ComSpec & " /c dir C:\", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    $test = ''
    While 1
        $line = StdoutRead($foo)
        If @error = -1 Then ExitLoop
        GUICtrlSetData($edit1, $line,1)
        $test &= $line
    WEnd

;~  GUICtrlSetData($edit1, $test)
    MsgBox(0,"result",$test)
EndFunc   ;==>CompileMe

You will see that output from DIR is correctly read but then it stays in While loop. But I don't know why and I don't know how to correct this.

Note that I added Opt('TrayIconDebug',1) to see where is execution ...

Edited by Zedna
Link to comment
Share on other sites

Now the result is scrambled and mixed? anyone knows why?

i try this

Func CompileMe()
Local $line,$foo[4],$i
$foo[0] = run(@comspec & " /c dir \\hppmapp01\d$\Backup_GP\*.bak /O:-d","",@SW_SHOW,$STDERR_CHILD + $STDOUT_CHILD)
$foo[1] = run(@comspec & " /c dir \\hppmapp01\d$\Backup_OTSys\*.bak /O:-d","",@SW_SHOW,$STDERR_CHILD + $STDOUT_CHILD)
$foo[2] = run(@comspec & " /c dir \\hppmapp01\d$\Backup_Payroll\*.bak /O:-d","",@SW_SHOW,$STDERR_CHILD + $STDOUT_CHILD)
$foo[3] = run(@comspec & " /c dir \\hppmapp01\d$\Backup_POrder\*.bak /O:-d","",@SW_SHOW,$STDERR_CHILD + $STDOUT_CHILD)
Do
;For $i=1 To 4
$line&=StdoutRead($foo[$i-1])
Next
until @error
    GUICtrlSetData($edit1,$line)
EndFunc

Help...again....please

Edited by Elkie
Link to comment
Share on other sites

When you set the values in $foo you are kicking off all of the commands at once. Then the results are all going to be interspersed. To kick them off one at a time, and capture all the results in one variable $line, try this:

Func CompileMe()
    Local $i, $pid, $line = ""
    Local $foo[4]
    $foo[0] = "\\hppmapp01\d$\Backup_GP\*.bak"
    $foo[1] = "\\hppmapp01\d$\Backup_OTSys\*.bak"
    $foo[2] = "\\hppmapp01\d$\Backup_Payroll\*.bak"
    $foo[3] = "\\hppmapp01\d$\Backup_POrder\*.bak"

    For $i=0 To 3
        $pid = run(@comspec & " /c dir " & $foo[$i] & " /O:-d","",@SW_SHOW,$STDERR_CHILD + $STDOUT_CHILD)
        Do
            $line &= StdoutRead($pid)
        Until @error
    Next

    GUICtrlSetData($edit1,$line)
EndFunc

If you meant to run all four Run() commands at once, then you need $line1, $line2, $line3, and $line4 to catch the seperate results in.

:shocked:

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...