.:: CODE SNIPPET ::.

"Your time is limited, so don't waste it living someone else's life"

How to execute batch file and read the out stream in NSIS


Plugin ExecDos will help us to do the title’s content easier.
First, we normally create an nsis wizard page like this

Plugin ExecDos will help us to do the title's content easier.
First, we normally create an nsis wizard page like this
Var hCtl_test
Var hCtl_test_ProgressBar1
Var hCtl_test_TextBox1
Var hCtl_test_Button1

Function fnc_test_Create
  
	; === test (type: Dialog) ===
	nsDialogs::Create 1018
	Pop $hCtl_test
	${If} $hCtl_test == error
		Abort
	${EndIf}
	!insertmacro MUI_HEADER_TEXT "Dialog title..." "Dialog subtitle..."
  
	; === ProgressBar1 (type: ProgressBar) ===
	${NSD_CreateProgressBar} 8u 7u 280u 13u ""
	Pop $hCtl_test_ProgressBar1
	SetCtlColors $hCtl_test_ProgressBar1 0x3399FF 0xF0F0F0
  
	; === TextBox1 (type: TextMultiline) ===
	nsDialogs::CreateControl EDIT ${DEFAULT_STYLES}|${ES_AUTOHSCROLL}|${ES_AUTOVSCROLL}|${ES_MULTILINE}|${ES_WANTRETURN}|${WS_HSCROLL}|${WS_VSCROLL} ${WS_EX_WINDOWEDGE}|${WS_EX_CLIENTEDGE} 8u 23u 280u 84u ""
	Pop $hCtl_test_TextBox1
	SendMessage $hCtl_test_TextBox1 ${ES_MULTILINE} 0 0
  
	; === Button1 (type: Button) ===
	${NSD_CreateButton} 238u 111u 49u 13u "Button1"
	Pop $hCtl_test_Button1
	${NSD_OnClick} $hCtl_test_Button1 onButtonClick
  
FunctionEnd

; dialog show function
Function fnc_test_Show
	Call fnc_test_Create
	nsDialogs::Show $hCtl_test
FunctionEnd
Function appendText
	Pop $0
	MessageBox MB_OK $0
FunctionEnd

Function onButtonClick
	GetFunctionAddress $R1 appendText
	ExecDos::exec /ASYNC /TOFUNC "batfile.bat" $R1
FunctionEnd
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: