TimG
16th July 2009 11:30 UTC
ExecDos TOWINDOW to capture batch file output
I would like to send the output of a batch file to a listbox. I've looked at the ExecDos ToWindow example but it's quite hard to follow. This is what I've tried:
!include nsDialogs.nsh
Var Dialog
Var Log
OutFile show_bat.exe
Page custom runScriptsPage leaveRunScriptsPage
Section -Main
SectionEnd
Function runScriptsPage
#Create dialog and show.
nsDialogs::Create 1018
Pop $Dialog
${NSD_CreateListBox} 0 20 100% 100u $Log
Pop $Log
nsDialogs::Show
#Run the batch file, send the output to the listbox.
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $1 $0 1200 #Get the window handle for the ListBox
ExecDos::exec /NOUNLOAD /TOWINDOW "dummy_sql.bat" "" $1
FunctionEnd
Function leaveRunScriptsPage
FunctionEnd
The batch file dummy_sql.bat:
@ECHO OFF
ECHO wait
SLEEP 5
ECHO done
I guess I'm doing more than one thing wrong. Any help would be appreciated.
Tim
Anders
16th July 2009 12:24 UTC
nsDialogs::Show needs to come AFTER ExecDos (nsDialogs::Show does not return until the dialog is finished)
you already have the listbox handle in $Log, why are you using sort of undocumented id's with GetDlgItem?
TimG
16th July 2009 12:43 UTC
I've updated the function
Function runScriptsPage
nsDialogs::Create 1018
Pop $Dialog
${NSD_CreateListBox} 0 20 100% 100u $Log
Pop $Log
ExecDos::exec /NOUNLOAD /TOWINDOW "dummy_sql.bat" "" $Log
nsDialogs::Show
FunctionEnd
It runs up to ExecDos then hangs.
Takhir
16th July 2009 18:46 UTC
!include nsDialogs.nsh
Var Dialog
Var Log
Var hcli
OutFile show_bat.exe
Page custom runScriptsPage leaveRunScriptsPage
Section -Main
SectionEnd
Function runScriptsPage
nsDialogs::Create 1018
Pop $Dialog
${NSD_CreateListBox} 0 20 100% 100u $Log
Pop $Log
ExecDos::exec /NOUNLOAD /ASYNC /TOWINDOW "dummy_sql.bat" "" $Log
Pop $hcli
nsDialogs::Show
FunctionEnd
Function leaveRunScriptsPage
ExecDos::wait $hcli
FunctionEnd
and
@ECHO OFF
ECHO wait
ping -n 3 127.0.0.1 >nul
ECHO done
cls
TimG
17th July 2009 09:45 UTC
Fantastic Takhir, problem solved.
I like to understand the fine details though; why does calling nsDialogs::Show before ExecDos::exec stop the output from being displayed?
Many thanks
Tim
Anders
17th July 2009 09:49 UTC
I already told you
TimG
17th July 2009 10:04 UTC
Sorry, my misunderstanding.
I thought you meant finished drawing the dialog, but experimenting a little I now understand it doesn't return until you actually move to the next (or previous) screen.
Takhir
17th July 2009 10:04 UTC
'Show' is sync operation. When Show() exits dialog is already destroyed.
But I had not time to check why ExecDos without /ASYNC before 'Show' not exits...