Snatching output from command line + adding time stamp

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
User avatar
Grovkillen
Automation Wizard
Posts: 1132
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Snatching output from command line + adding time stamp

Post by Grovkillen » Thu Nov 17, 2016 8:28 pm

Hi there,

I'm trying to first of all time stamp output (in this example from ping) and I do get it to work when manually doing it in the Command Line Console. But when I try to do it through MS using RunProgram I cannot get it to work.

Image

Vbs code in "timestampLog.vbs":

Code: Select all

Dim str
Do While Not WScript.StdIn.AtEndOfStream
  str = WScript.StdIn.ReadLine
  WScript.StdErr.WriteLine "[" & now & "] " & str
Loop
Any idea what I'm doing wrong?
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
JRL
Automation Wizard
Posts: 3531
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Snatching output from command line + adding time stamp

Post by JRL » Fri Nov 18, 2016 4:50 am

Tried several redirects to file but could not get the date stamp in the file. There is probably a way to do this completely in VBScript and I'm sure I could get something similar using DOS and Macro Scheduler without VBScript but this gives you what you asked for.

Code: Select all

Let>ClearCB=
PutClipBoard>ClearCB
Let>RP_Wait=0
Let>RP_Windowmode=1

RunProgram>cmd /k ping 192.168.0.102 | cscript //nologo %desktop_dir%\timestamplog.vbs

WaitWindowOpen>cmd.exe*
Wait>1
GetWindowPos>cmd.exe*,WinX,WinY
Add>WinX,50
Add>WinY,50

Label>PingExists
Wait>0.2
ProcessExists>Ping.exe,vRes
If>vRes=True
  Goto>PingExists
EndIf

SetFocus>cmd.exe*
MouseMove>WinX,WinY
Wait>0.2
RClick

Wait>0.2
Press down * 4
Wait>0.2
Press Enter
Wait>0.2
Press enter
Wait>0.2
GetClipBoard>vData
CloseWindow>cmd.exe*
Let>Msg_width=500
Let>msg_height=300
MessageModal>vData

User avatar
Grovkillen
Automation Wizard
Posts: 1132
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Snatching output from command line + adding time stamp

Post by Grovkillen » Fri Nov 18, 2016 7:04 am

Thanks JRL for pointing me in the right direction!

Here's the working code:

Code: Select all

Let>RP_Wait=0
Let>RP_Windowmode=1
RunProgram>cmd /k ping 192.168.0.102 | cscript //nologo %desktop_dir%\timestamplog.vbs 2>> %desktop_dir%\timestamplog.log
WaitWindowOpen>cmd.exe*
The secret here is the "2>>" the "2" is telling cmd to output only StdErr (which we converted the StdIn to in the vbs file). The first ">" is telling cmd to output to file, the second ">" tells cmd to append to the file. If the second ">" is left out the file will be over written.
Let>ME=%Script%

Running: 15.0.27
version history

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts