Last active
July 21, 2024 05:32
Revisions
-
codeartery renamed this gist
Sep 5, 2020 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
codeartery revised this gist
May 4, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ Function CmdOut( pCmd ) REM@returns ' CmdOut <string> - The output of the command. REM@author ' Jeremy England, http://codeartery.com/ REM@mini ' Function CmdOut(p):Dim w,e,r,o:Set w=CreateObject("WScript.Shell"):Set e=w.Exec("Cmd.exe"):e.StdIn.WriteLine p&" 2>&1":e.StdIn.Close:While(InStr(e.StdOut.ReadLine,">"&p)=0)::Wend:Do:o=e.StdOut.ReadLine:If(e.StdOut.AtEndOfStream)Then:Exit Do:Else:r=r&o&vbLf:End If:Loop:CmdOut=r:End Function Dim oWss, oExe, Return, Output -
codeartery created this gist
Dec 30, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ Function CmdOut( pCmd ) REM@description ' Run a command prompt command and get its output. REM@params ' pCmd <string> - A command prompt command. REM@returns ' CmdOut <string> - The output of the command. REM@author ' Jeremy England, https://codeartery.com/ REM@mini ' Function CmdOut(p):Dim w,e,r,o:Set w=CreateObject("WScript.Shell"):Set e=w.Exec("Cmd.exe"):e.StdIn.WriteLine p&" 2>&1":e.StdIn.Close:While(InStr(e.StdOut.ReadLine,">"&p)=0)::Wend:Do:o=e.StdOut.ReadLine:If(e.StdOut.AtEndOfStream)Then:Exit Do:Else:r=r&o&vbLf:End If:Loop:CmdOut=r:End Function Dim oWss, oExe, Return, Output Set oWss = CreateObject( "WScript.Shell" ) Set oExe = oWss.Exec( "Cmd.exe" ) Call oExe.StdIn.WriteLine( pCmd & " 2>&1" ) Call oExe.StdIn.Close() While( InStr( oExe.StdOut.ReadLine, ">" & pCmd ) = 0 ) :: Wend Do : Output = oExe.StdOut.ReadLine() If( oExe.StdOut.AtEndOfStream )Then Exit Do Else Return = Return & Output & vbLf End If Loop CmdOut = Return End Function This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ REM@usage ' Put the full or mini class/sub/function in your script to use. Function CmdOut(p):Dim w,e,r,o:Set w=CreateObject("WScript.Shell"):Set e=w.Exec("Cmd.exe"):e.StdIn.WriteLine p&" 2>&1":e.StdIn.Close:While(InStr(e.StdOut.ReadLine,">"&p)=0)::Wend:Do:o=e.StdOut.ReadLine:If(e.StdOut.AtEndOfStream)Then:Exit Do:Else:r=r&o&vbLf:End If:Loop:CmdOut=r:End Function ' returns the result of whatever command you run Dim Result Result = CmdOut( "ECHO Hello, world!" ) MsgBox Result ' if you run with cscript instead of wscript you can see the full output when using wscript.echo because msgbox has a character limit Dim IpConfig IpConfig = CmdOut( "ipconfig /all" ) WScript.Echo IpConfig