Redirect script output to log file

Home Forums Scripting General Scripting Redirect script output to log file

Viewing 1 post (of 1 total)
  • Author
    Posts
  • Avatar
    igor7
    Member
    #157049

    Hi!!
    I need redirect output of following script into log file. The script bellows retrieve WAN IP address using IE:

    Option Explicit
    Dim dtmStart, lngSeconds

    dtmStart = Now
    WScript.Echo “InternetExplorer.Application ” _
    & MyIP_IE( ) & ” (” _
    & DateDiff( “s”, dtmStart, Now ) & ” seconds)”

    Function MyIP_IE( )
    ‘ Name: MyIP_IE
    ‘ Function: Display your WAN IP address using Internet Explorer
    ‘ Usage: ret = MyIP_IE( )
    ‘ Returns: WAN (or global) IP address

    ‘ This script uses WhatIsMyIP.com’s automation page
    ‘ [URL]http://automation.whatismyip.com/n09230945.asp[/URL]
    ‘ Script Source [URL=”http://www.robvanderwoude.com/”]http://www.robvanderwoude.com[/URL]
    Dim blnTimedOut, i, objIE, objMatch, objRE, strText, strURL
    ‘ Return value if IP address couldn’t be retrieved
    MyIP_IE = “0.0.0.0”
    ‘ Open the appropriate URL in Internet Explorer
    strURL = “[URL]http://automation.whatismyip.com/n09230945.asp[/URL]”
    Set objIE = CreateObject( “InternetExplorer.Application” )
    objIE.Visible = False
    objIE.Navigate2 strURL
    ‘ Wait till IE is ready
    i = 0
    blnTimedOut = False
    Do While objIE.Busy
    WScript.Sleep 100
    i = i + 1
    ‘ Time out after 10 seconds
    If i > 100 Then
    blnTimedOut = True
    Exit Do
    End If
    Loop
    ‘ Retrieve the URL’s text
    If Not blnTimedOut Then MyIP_IE = objIE.Document.Body.InnerText
    ‘ Close the Internet Explorer session
    objIE.Quit
    Set objIE = Nothing
    End Function
    [/CODE]

    I finnd similar thread: [URL]http://forums.petri.com/showthread.php?t=29121[/URL] where Rems advice to run the script from the command line (with cscript) and redirect the output to a text file. I’ve created shortcut, edited his properties as following:

    [CODE]
    %comspec% /c “%windir%system32cscript.exe” //NoLogo “%userprofile%DesktopWANIP.vbs” >”%userprofile%DesktopWANIP.log”
    [/CODE]

    [COLOR=#555a5f][FONT=Verdana]But whenever I’m running this shortcut it create an empty WANIP.log file on the desktop (I’m running it on Windows 7 computer with elevated privileges).[/FONT][/COLOR]
    [COLOR=#555a5f][FONT=Verdana]By the same token, script itself working normally,- it return echo message with my current WAN IP address. So, why it doesn’t redirect script output into the log file?[/FONT][/COLOR][CODE]
    Option Explicit
    Dim dtmStart, lngSeconds

    dtmStart = Now
    WScript.Echo “InternetExplorer.Application ” _
    & MyIP_IE( ) & ” (” _
    & DateDiff( “s”, dtmStart, Now ) & ” seconds)”

    Function MyIP_IE( )
    ‘ Name: MyIP_IE
    ‘ Function: Display your WAN IP address using Internet Explorer
    ‘ Usage: ret = MyIP_IE( )
    ‘ Returns: WAN (or global) IP address

    ‘ This script uses WhatIsMyIP.com’s automation page
    http://automation.whatismyip.com/n09230945.asp
    ‘ Script Source http://www.robvanderwoude.com
    Dim blnTimedOut, i, objIE, objMatch, objRE, strText, strURL
    ‘ Return value if IP address couldn’t be retrieved
    MyIP_IE = “0.0.0.0”
    ‘ Open the appropriate URL in Internet Explorer
    strURL = “http://automation.whatismyip.com/n09230945.asp
    Set objIE = CreateObject( “InternetExplorer.Application” )
    objIE.Visible = False
    objIE.Navigate2 strURL
    ‘ Wait till IE is ready
    i = 0
    blnTimedOut = False
    Do While objIE.Busy
    WScript.Sleep 100
    i = i + 1
    ‘ Time out after 10 seconds
    If i > 100 Then
    blnTimedOut = True
    Exit Do
    End If
    Loop
    ‘ Retrieve the URL’s text
    If Not blnTimedOut Then MyIP_IE = objIE.Document.Body.InnerText
    ‘ Close the Internet Explorer session
    objIE.Quit
    Set objIE = Nothing
    End Function
    [/CODE]

    I finnd similar thread: http://forums.petri.com/showthread.php?t=29121 where Rems advice to run the script from the command line (with cscript) and redirect the output to a text file. I’ve created shortcut, edited his properties as following:

    %comspec% /c “%windir%system32cscript.exe” //NoLogo “%userprofile%DesktopWANIP.vbs” >”%userprofile%DesktopWANIP.log”
    [/CODE]

    [COLOR=#555a5f][FONT=Verdana]But whenever I’m running this shortcut it create an empty WANIP.log file on the desktop (I’m running it on Windows 7 computer with elevated privileges).[/FONT][/COLOR]
    [COLOR=#555a5f][FONT=Verdana]By the same token, script itself working normally,- it return echo message with my current WAN IP address. So, why it doesn’t redirect script output into the log file?[/FONT][/COLOR][CODE]
    %comspec% /c “%windir%system32cscript.exe” //NoLogo “%userprofile%DesktopWANIP.vbs” >”%userprofile%DesktopWANIP.log”
    [/CODE]

    But whenever I’m running this shortcut it create an empty WANIP.log file on the desktop (I’m running it on Windows 7 computer with elevated privileges).
    By the same token, script itself working normally,- it return echo message with my current WAN IP address. So, why it doesn’t redirect script output into the log file?

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.