Skip to content
⌘ NSIS Forum Archive

Is it Possible to Capture An Applications Output And Place it Into $0?

5 posts

vbgunz#

Is it Possible to Capture An Applications Output And Place it Into $0?

Hello,

I can pretty much redirect an applications output to a file and read it from there *but* is there a way to capture the output directly into a $Var?

e.g. "$COMSPEC /C SET" would return the environment variables on the system. I can redirect this info to a file *but* is it possible to redirect it to a $Var so to display it's output in a MessageBox or something similar?

I searched for this and conclude it is not a popular question. Is this possible? Any help is greatly appreciated! Thank you!

--
Best Regards
Victor B. Gonzalez
kichik#
You can use nsExec's ExecToStack and Pop the result into $0. You can also use ExecToLog to output it directly to the installation page log.
vbgunz#edited
Thank you Kichik!

Kichik, Pop $0 returns the error code (0,1, timeout, etc). I also have to Pop $1 to get what it is I am looking for. Is this correct?

# Error Code = $0. Output = $1.
nsExec::ExecToStack '$COMSPEC /C SET'
Pop $0
Pop $1
MessageBox MB_OK "$1"

Thank you Kichik!
Takhir#
A full set of env. vars may take more then 1 kB - string limit for common NSIS build (8 kB in special build). So if you don't need all vars, use ReadEnvStr NSIS instruction.
In the nsExec test.nsi I see 2 output strings in the ExecToStack sample and single string for ExecToLog, so your code looks correct.
vbgunz#
Thank you Takhir!

Thank you very much for your insight on this. I needed the confirmation and am grateful for your time Takhir 🙂

Thank you both again!