hello.
i trying make a custom method what causes return a char with system output.
the pseudocode like this.
char *my_Out(char *in ){
in = system ("ping %s",in);
return in;
}
thanks for the help.
hello.
i trying make a custom method what causes return a char with system output.
the pseudocode like this.
char *my_Out(char *in ){
in = system ("ping %s",in);
return in;
}
thanks for the help.
You can use popen
, which returns you a stream that you can read the output from. By reading until end-of-file, into a string (probably one that dynamically grows as necessary), you can implement what you're asking for.
A few things
system()
is not a printf style function. You'll need to use sprintf()
to create your argument before.system()
's return value is an int, non a charWhat are you trying to do? It looks like all this function does is run ping
(which, without the -c argument, will never finish running on linux).
Duplicate the stdout to some other file descriptor by using dup2.After the execution of the command read all the lines from the file using that file descriptor and return it.