-
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 :D
-
try this...
system("ping 127.0.0.1 > pingfile.txt");
-
"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".
-
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.
-
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".
-
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?
-
-
naaaa, the star crunch has always been the best :D
-
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
-
ohhh i like those too yummm