Code: Select all
;-------- http://www.autohotkey.com/board/topic/96903-simplified-versions-of-seans-stdouttovar/ ---
;---------- FUNCTION StdOutStream SKAN / HotKeyIt -----------
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
edcol1=gray
cmd1:="ping -n 4 -w 1000 www.google.com"
GUI,2:+AlwaysOnTop
Gui,2: Color, ControlColor, Black
Gui,2: Font, ,Fixedsys
;Gui,2: Font,s15,Terminal
Gui,2:Add, Edit , x5 y10 w800 h510 c%edcol1% vF1,
Gui,2:add, button, x5 y540 w100 h25 gDos1 ,DOS
Gui,2:add, button, x120 y540 w100 h25 gPing1 ,Ping
Gui,2:add, button, x240 y540 w100 h25 gDate1 ,DATE
Gui,2:add, button, x360 y540 w140 h25 gXcopy1,Xcopy-Help
GUI,2:show, NA W820 H580 X20 Y0, StdOutStream
return
;----------------------------------------------------------
2GuiClose:
ExitApp
;------------------------
dos1:
Gui,2:submit,nohide
Guicontrol,2:,F1,
e4x:="
(ltrim join&
echo off
ver
vol
date /t
time /t
netstat -an
path
xcopy /?"
)
aaf:=% StdOutStream(comspec " /k " e4x)
Guicontrol,2:,F1,%aaf%
e4x=
aaf=
return
;------------------------
;------------------------
ping1:
Guicontrol,2:,F1,
aaf:=% StdOutStream(cmd1 , "StdOutStream_Callback")
StdOutStream_Callback( data, n ) {
Static D
D .= data
Guicontrol,2:,F1,%d%
if ! ( n ) {
Tooltip % D := ""
Return
}
}
return
;---------------------------------------------------
date1:
Gui,2:submit,nohide
Guicontrol,2:,F1,
e5x:="
(ltrim join&
ver
date"
)
aaf:=% StdOutStream(comspec " /k " e5x)
Guicontrol,2:,F1,%aaf%
e5x=
aaf=
return
;------------------------
xcopy1:
Gui,2:submit,nohide
Guicontrol,2:,F1,
e6x:="
(ltrim join&
ver
echo off
echo xcopy /? HELP=
xcopy /?"
)
aaf:=% StdOutStream(comspec " /k " e6x)
Guicontrol,2:,F1,%aaf%
e6x=
aaf=
return
;------------------------
;========================================================================================
StdOutStream( sCmd, Callback = "" ) { ; Modified : SKAN 31-Aug-2013 http://goo.gl/j8XJXY
Static StrGet := "StrGet" ; Thanks to : HotKeyIt http://goo.gl/IsH1zs
; Original : Sean 20-Feb-2007 http://goo.gl/mxCdn
DllCall( "CreatePipe", UIntP,hPipeRead, UIntP,hPipeWrite, UInt,0, UInt,0 )
DllCall( "SetHandleInformation", UInt,hPipeWrite, UInt,1, UInt,1 )
VarSetCapacity( STARTUPINFO, 68, 0 ) ; STARTUPINFO ; http://goo.gl/fZf24
NumPut( 68, STARTUPINFO, 0 ) ; cbSize
NumPut( 0x100, STARTUPINFO, 44 ) ; dwFlags => STARTF_USESTDHANDLES = 0x100
NumPut( hPipeWrite, STARTUPINFO, 60 ) ; hStdOutput
NumPut( hPipeWrite, STARTUPINFO, 64 ) ; hStdError
VarSetCapacity( PROCESS_INFORMATION, 16 ) ; PROCESS_INFORMATION ; http://goo.gl/b9BaI
If ! DllCall( "CreateProcess", UInt,0, UInt,&sCmd, UInt,0, UInt,0 ; http://goo.gl/USC5a
, UInt,1, UInt,0x08000000, UInt,0, UInt,0
, UInt,&STARTUPINFO, UInt,&PROCESS_INFORMATION )
Return ""
, DllCall( "CloseHandle", UInt,hPipeWrite )
, DllCall( "CloseHandle", UInt,hPipeRead )
, DllCall( "SetLastError", Int,-1 )
hProcess := NumGet( PROCESS_INFORMATION, 0 )
hThread := NumGet( PROCESS_INFORMATION, 4 )
DllCall( "CloseHandle", UInt,hPipeWrite )
AIC := ( SubStr( A_AhkVersion, 1, 3 ) = "1.0" ) ; A_IsClassic
VarSetCapacity( Buffer, 4096, 0 ), nSz := 0
While DllCall( "ReadFile", UInt,hPipeRead, UInt,&Buffer, UInt,4094, UIntP,nSz, Int,0 ) {
tOutput := ( AIC && NumPut( 0, Buffer, nSz, "Char" ) && VarSetCapacity( Buffer,-1 ) )
? Buffer : %StrGet%( &Buffer, nSz, "CP850" )
Isfunc( Callback ) ? %Callback%( tOutput, A_Index ) : sOutput .= tOutput
}
DllCall( "GetExitCodeProcess", UInt,hProcess, UIntP,ExitCode )
DllCall( "CloseHandle", UInt,hProcess )
DllCall( "CloseHandle", UInt,hThread )
DllCall( "CloseHandle", UInt,hPipeRead )
DllCall( "SetLastError", UInt,ExitCode )
Return Isfunc( Callback ) ? %Callback%( "", 0 ) : sOutput
}
;======================== end script ======================================