Archive: Read util output


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.


Try ExecDos plugin (search Wiki).

-Stu


ExecDos can't return util's output.

Am I right?


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


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.


And after that i can pop output from nsis stack?
Or log file is neccessary anyway?


The best way for you is to re-write this part of code and to add pushstring on every \n instead of WriteFile.


Works fine thank you.


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

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.


Be careful with that one. If your output length exceeds 1023 characters it will be truncated. If not then you needn't worry :)

-Stu


OK - non empty lines go to stack with /TOSTACK option http://nsis.sourceforge.net/ExecDos_plug-in


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