- NSIS Discussion
- Read util output
Archive: Read util output
Kerzh
25th July 2006 17:30 UTC
Read util output
Hi guys.
I have an external VB6 console util that make some actions return code to OS and writes to standard output.
I need to run it from NSIS in async mode beacuse it updates NSIS GUI (moves progress bar and writes to log).
At the end of the work i generate leave page event and come to leave callback function of my custom page. Can i get here error code and output of my util?
Or write these data to file is the only solution?
Thank you.
Afrow UK
25th July 2006 17:37 UTC
Try ExecDos plugin (search Wiki).
-Stu
Kerzh
26th July 2006 09:56 UTC
ExecDos can't return util's output.
Am I right?
Afrow UK
26th July 2006 10:12 UTC
Yeh, I'm afraid you are. It can only log the standard out to a text file, but from my experience that only happens when the process has finished.
With nsExec, you can capture the output on the NSIS stack, but it puts all the output into one stack item (which is only 1024 characters), rather than one line per stack item.
All I can suggest is that you convert your code to C/C++ and use it in a plugin, which you can run the code under a separate thread (unless you can do that in VB6).
See Control\ExDll\exdll.c in the NSIS source distribution for an example.
-Stu
Takhir
26th July 2006 10:44 UTC
ExecDos can put output to file, so if you need 'live' output - just add fflush(NULL) after line 195 in execDos.c and rebuild dll. Or do this on end-of-line chars (\n) only instead of every char.
Kerzh
26th July 2006 11:16 UTC
And after that i can pop output from nsis stack?
Or log file is neccessary anyway?
Takhir
26th July 2006 11:47 UTC
The best way for you is to re-write this part of code and to add pushstring on every \n instead of WriteFile.
Kerzh
26th July 2006 13:54 UTC
Works fine thank you.
Afrow UK
26th July 2006 13:55 UTC
Ideally this could be a new feature for the DLL. It can be very useful.
To prevent the opcode error (to many Pops when the stack is empty) something like this should work:
Push "/start"
# call plugin with async
Pop $0 # handle
Loop:
Pop $1 # stack item
StrCmp $1 "/end" Done
StrCmp $1 "/start" 0 +4
Push "/start"
Sleep 100
Goto Loop
# Do somthing here with $1.
Goto Loop
Done:
The plugin will have to put "/end" on the stack when the process finishes otherwise you will get an infinite loop.
-Stu
Kerzh
26th July 2006 17:47 UTC
In my case, i put all output to the one stack item and popping it
Pop $0 ; cmd result
Pop $1 ; cmd output
$1 can contain '\n' symbols and it semms to work.
Afrow UK
26th July 2006 18:32 UTC
Be careful with that one. If your output length exceeds 1023 characters it will be truncated. If not then you needn't worry :)
-Stu
Takhir
26th July 2006 19:43 UTC
OK - non empty lines go to stack with /TOSTACK option http://nsis.sourceforge.net/ExecDos_plug-in
Afrow UK
26th July 2006 22:41 UTC
Lovely :)
My code is a bit stupid. You could just Push "/stop" before calling the plugin and when that item is Popped you know you're done.
-Stu