Skip to content
⌘ NSIS Forum Archive

Read util output

13 posts

Kerzh#

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#
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#
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.
Takhir#
The best way for you is to re-write this part of code and to add pushstring on every \n instead of WriteFile.
Afrow UK#
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#
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#
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#
OK - non empty lines go to stack with /TOSTACK option http://nsis.sourceforge.net/ExecDos_plug-in
Afrow UK#
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