Questions regarding ping...

I have written a program that pings all the computers on my home network, but the output isn't what I expected:
[code]
system("cls");
cout << "
Ping with the router is: ";
system("ping 192.168.0.1");
cout << "
Ping with laptop is: ";
system("ping 192.168.0.2");
.
.
.
[/code]
My output is:

Pinging 192.168.0.1 with 32 bytes of data:

Reply from 192.168.0.1:bytes=32 time=7ms TTL=254
.
.
.
Minimum = 3ms, Maximum = 11 ms, Average = 6ms

Ping with the router is:
Ping with laptop is:

Why aren't the pings displayed after each cout? Also, how can I store the values returned from the ping so I don't have to display the entire message, just data that I want to display.

Thanks,

Comments

  • below is the output I got from your program, using VC++ 6.0 compiler. I didn't change the ip addresses, so naturally I would expece the pings to fail. But it doesn't appear to have the same problem that you describe, about lines out of order.


    [code]

    Ping with the router is:
    Pinging 192.168.0.1 with 32 bytes of data:

    Reply from 140.175.68.1: Destination net unreachable.
    Request timed out.
    Reply from 140.175.68.1: Destination net unreachable.
    Request timed out.

    Ping statistics for 192.168.0.1:
    Packets: Sent = 4, Received = 2, Lost = 2 (50% loss),
    Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

    Ping with laptop is:
    Pinging 192.168.0.2 with 32 bytes of data:

    Request timed out.
    Reply from 140.175.68.1: Destination net unreachable.
    Reply from 140.175.68.1: Destination net unreachable.
    Reply from 140.175.68.1: Destination net unreachable.

    Ping statistics for 192.168.0.2:
    Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
    Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

    [/code]

    As for your other question -- you can redirect the output to a file then read and parse the file later.
    [code]
    system("ping 192.168.0.1 [red]>file.txt"[/red]);
    system("ping 192.168.0.2 [red] >>file.txt"[/red]);

    [/code]
  • : I have written a program that pings all the computers on my home network, but the output isn't what I expected:
    : [code]
    : system("cls");
    : cout << "
    Ping with the router is: ";
    : system("ping 192.168.0.1");
    : cout << "
    Ping with laptop is: ";
    : system("ping 192.168.0.2");
    : .
    : .
    : .
    : [/code]
    : My output is:
    :
    : Pinging 192.168.0.1 with 32 bytes of data:
    :
    : Reply from 192.168.0.1:bytes=32 time=7ms TTL=254
    : .
    : .
    : .
    : Minimum = 3ms, Maximum = 11 ms, Average = 6ms
    :
    : Ping with the router is:
    : Ping with laptop is:
    :
    : Why aren't the pings displayed after each cout? Also, how can I store the values returned from the ping so I don't have to display the entire message, just data that I want to display.
    :
    : Thanks,
    :

    What operating system are you using?

  • :
    : What operating system are you using?
    :
    :
    I have ran this program on my laptop which is running winXP Home and my desktop that is running winXP Pro with the same output. Both computers are using VC++ 6.0.
  • : : I have written a program that pings all the computers on my home network, but the output isn't what I expected:
    : : [code]
    : : system("cls");
    : : cout << "
    Ping with the router is: ";
    : : system("ping 192.168.0.1");
    : : cout << "
    Ping with laptop is: ";
    : : system("ping 192.168.0.2");
    : : .
    : : .
    : : .
    : : [/code]
    : : My output is:
    : :
    : : Pinging 192.168.0.1 with 32 bytes of data:
    : :
    : : Reply from 192.168.0.1:bytes=32 time=7ms TTL=254
    : : .
    : : .
    : : .
    : : Minimum = 3ms, Maximum = 11 ms, Average = 6ms
    : :
    : : Ping with the router is:
    : : Ping with laptop is:
    : :
    : : Why aren't the pings displayed after each cout? Also, how can I store the values returned from the ping so I don't have to display the entire message, just data that I want to display.
    : :
    : : Thanks,
    : :
    :
    : What operating system are you using?
    :
    :

    Very odd. Is it possible that the XP system considers a "system" call a seperate multitasked thread, and is placing a higher priority on that system call than it does on your executable?
  • : [code]
    : system("ping 192.168.0.1 [red]>file.txt"[/red]);
    : system("ping 192.168.0.2 [red] >>file.txt"[/red]);
    :
    : [/code]
    :
    Thanks for the tip. However, when I try that I get an error in the console window that says "The process cannot access the file because it is being used by another process." Here is my code:

    [code]
    fstream iofile;
    iofile.open("C:\MyProj\tinkering\pingdata.txt", ios::out);

    if(!iofile.good())
    {
    cout << "
    There has been an error!" << endl;
    }
    else
    {
    system("ping 192.168.0.1 >> pingdata.txt");
    iofile.close();
    }
    [/code]

    Thanks,
  • : : [code]
    : : system("ping 192.168.0.1 [red]>file.txt"[/red]);
    : : system("ping 192.168.0.2 [red] >>file.txt"[/red]);
    : :
    : : [/code]
    : :
    : Thanks for the tip. However, when I try that I get an error in the console window that says "The process cannot access the file because it is being used by another process." Here is my code:
    :
    : [code]
    : fstream iofile;
    : iofile.open("C:\MyProj\tinkering\pingdata.txt", ios::out);
    :
    : if(!iofile.good())
    : {
    : cout << "
    There has been an error!" << endl;
    : }
    : else
    : {
    : system("ping 192.168.0.1 >> pingdata.txt");
    : iofile.close();
    : }
    : [/code]
    :
    : Thanks,
    :


    [code]
    int main()
    {
    system("ping 192.168.0.1 > pingdata.txt");

    return 0;
    }
    [/code]
    [italic][blue]To understand recursive, first you need to understand recursive[/blue][/italic]

  • : : : I have written a program that pings all the computers on my home network, but the output isn't what I expected:
    : : : [code]
    : : : system("cls");
    : : : cout << "
    Ping with the router is: ";
    : : : system("ping 192.168.0.1");
    : : : cout << "
    Ping with laptop is: ";
    : : : system("ping 192.168.0.2");
    : : : .
    : : : .
    : : : .
    : : : [/code]
    : : : My output is:
    : : :
    : : : Pinging 192.168.0.1 with 32 bytes of data:
    : : :
    : : : Reply from 192.168.0.1:bytes=32 time=7ms TTL=254
    : : : .
    : : : .
    : : : .
    : : : Minimum = 3ms, Maximum = 11 ms, Average = 6ms
    : : :
    : : : Ping with the router is:
    : : : Ping with laptop is:
    : : :
    : : : Why aren't the pings displayed after each cout? Also, how can I store the values returned from the ping so I don't have to display the entire message, just data that I want to display.
    : : :
    : : : Thanks,
    : : :
    : :
    : : What operating system are you using?
    : :
    : :
    :
    : Very odd. Is it possible that the XP system considers a "system" call a seperate multitasked thread, and is placing a higher priority on that system call than it does on your executable?
    :


    Windows will run system() calls in cmd.exe, which is a separate process.
    If you check in the task manager during execution of a system() call, you will see the process while the command is executed. In this case ping.exe will be started as well.

    The program should wait for cmd.exe to finish, which is handled by the compiler's implementation of system(). I'm not sure, but I think this might be a compiler specific issue.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories