checking sys commands

This is a discussion on checking sys commands within the C++ Programming forums, part of the General Programming Boards category; How would i check a system command? example: Code: system("ping 127.0.0.1"); and i wanted it to store it to a ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    206

    Question checking sys commands

    How would i check a system command? example:
    Code:
    system("ping 127.0.0.1");
    and i wanted it to store it to a txt if it was right, and go to ... say 62.4.55.211 after it and do the same, etc etc. Plz could someone help me with validating system commands? thanx

  2. #2
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    try this...
    system("ping 127.0.0.1 > pingfile.txt");

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    "if it was right" . as in "if it was a real ip". as in "if it was NOT a wrong ip". as in "if it is a wrong ip dont write it to the file".

  4. #4
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    Due to the nature of the system command, I don't think what you're asking is possible if just using the system command.

    Don't jump on people for trying to help - you're the lazy bastard who won't look up system's prototype and figure out what the return value means.

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    dont get crazy turbo. It's called "I can't find it". as in "I needed some help from people in real life". As in "I came for help". As in "I asked for help here". As in "I wasnt beingrude". As in "but now i am". As in "Because you are being the bastard". As in "SHOVE OFF".

  6. #6
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    Thank you oh so much for making my impending departure from this board worthwhile. Dick.

    Besides, you think I just pulled the answer I gave you out of the air? I looked it up in a book... Pretty bloody difficult. What sort of effort did you make before posting, besides putting down your hoho and mayonnaise sandwich?

  7. #7
    Registered User Sekti's Avatar
    Join Date
    Feb 2002
    Posts
    163
    mmm i like hohos
    +++
    ++
    + Sekti
    ++
    +++

  8. #8
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    naaaa, the star crunch has always been the best

  9. #9
    Registered User
    Join Date
    Aug 2001
    Location
    computers/ theatre, travelingstudentL>- Northern California NativeNorthern California3D&Tie-DyeStudent1>. Admirer of C Bangalore Net surfingTeacher >/ >0 nagpurteaching >1  >2
    Posts
    61
    Now back to the original problem

    try a variation of this:

    #include <stdlib.h>
    #include <stdio.h>
    char command[128];
    FILE *fPtr;
    int first = 127;
    int second = 0;
    int third = 0;
    int forth = 1;

    sprintf(command, "ping %d.%d.%d.%d\0", first, second, third, forth);
    // when creating the ping command, add an option for
    // how many times it should ping, I can not remember
    // what the option is

    fPtr = popen(command, "r");
    if(fPtr == NULL) return -1;

    while(!feof(fPtr))
    {
    // use fscanf or fgets to get the output from the command
    // parse the output for what you want
    }

    popen creates a stream from the system command to your program

  10. #10
    Registered User Sekti's Avatar
    Join Date
    Feb 2002
    Posts
    163
    ohhh i like those too yummm
    +++
    ++
    + Sekti
    ++
    +++

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 10:38 AM
  2. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 06:59 PM
  3. Problems about gcc installation
    By kevin_cat in forum Linux Programming
    Replies: 4
    Last Post: 08-09-2005, 10:05 AM
  4. Replies: 2
    Last Post: 05-25-2004, 06:10 PM
  5. Dos commands hehe
    By Carp in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 01-17-2003, 02:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21