Sign in to follow this  
Followers 0
dufran3

Write out to a command prompt?

10 posts in this topic

Below is a function I wrote for pinging a computer. Is there anyway, that instead of writing the results to a logfile/console/msgbox, that I could write them out to a command prompt window?

Func _PingCheck($name, $logpath = '')
    If $logpath == '' Then
        $logpath = 'C:\pinglog.txt'
    EndIf
    $var = Ping($name,250)
    $FileOpen = FileOpen($logpath,1)
    If $var Then
        FileWriteLine($FileOpen,$name & ' status is "up"')
        FileWriteLine($FileOpen,"Online, roundtrip was: " & $var & ' ms')
    Else
        Select 
            Case @error == 1
                FileWriteLine($FileOpen,"An error occured with number: " & @error & @CRLF & 'Host is offline')
            Case @error == 2
                FileWriteLine($FileOpen,"An error occured with number: " & @error & @CRLF & 'Host is unreachable')
            Case @error == 3
                FileWriteLine($FileOpen,"An error occured with number: " & @error & @CRLF & 'Bad destination')
            Case @error == 4
                FileWriteLine($FileOpen,"An error occured with number: " & @error & @CRLF & 'Other errors')
        EndSelect
    EndIf
EndFunc

Share this post


Link to post
Share on other sites



Send()


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Really, I thought send was to send keys and text to a window

Share this post


Link to post
Share on other sites

Really, I thought send was to send keys and text to a window

http://www.autoitscript.com/forum/index.ph...st&p=309892

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Hrmm...not sure you are getting at what i'm trying to do. I don't want to send the window a command. Or type anything into the window. I want to output my error messages to a command prompt...

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hrmm...not sure you are getting at what i'm trying to do. I don't want to send the window a command. Or type anything into the window. I want to output my error messages to a command prompt...

To be honest, I'm not sure, if no one else is 100%, maybe google could be your friend.

Run(@ComSpec & ' /?')
Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Hrmm...not sure you are getting at what i'm trying to do. I don't want to send the window a command. Or type anything into the window. I want to output my error messages to a command prompt...

O.K., so what do you think this will do?

Send("This is not a command and also I don't type anything into the window. It's just my error message")

I'll tell you. It will just write that text into the command window (IF you opened one and it had the focus). However, WHAT are you going to do with that command windows??? I don't get it .....


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

Why not use the version of PING that comes with the OS in a batch file and pipe/append the output to a text file which can then be parsed later?

ping www.microsoft.com >> c:\pinglog.txt
Type PING /? in a command box to see relevant parameters...

Share this post


Link to post
Share on other sites

The OP wants to display the results in a command prompt like window:

@OP: I'd recommend writing the data to a text document then displaying that in notepad.

Or, look at http://www.autoitscript.com/forum/index.php?showtopic=19665

#)

Share this post


Link to post
Share on other sites

Really, I thought send was to send keys and text to a window

it is:
_PingCheck("google.com")

_PingCheck("cnn.com")

Func _PingCheck($name)
    Run("cmd")
    WinWait("C:\WINDOWS\system32\cmd.exe")
    $var = Ping($name, 250)
    Select
        Case @error == 1
            Send("An error occured with number: " & _
                    @error & '  Host is offline')
        Case @error == 2
            Send("An error occured with number: " & _
                    @error & '  Host is unreachable')
        Case @error == 3
            Send("An error occured with number: " & _
                    @error & '  Bad destination')
        Case @error == 4
            Send("An error occured with number: " & _
                    @error & '  Other errors')
    EndSelect
    If $var Then Send(' status is "up" Online, roundtrip was: ' & $var & ' ms')
    If $var = 0 Then Send(' Ping failed')
EndFunc   ;==>_PingCheck

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0