Hi,
I am trying to write some code in order to communicate with a telnet clent from a c++ application. My idea was to open a telnet session with popen and to use the input/output pipes to communicate but it does not seem to work. When I test, the program says that the pipes are not usable:
"
ioctl: is a good pipe ? =-1
isastream: is a good pipe ? =0
"
I know that the network communication can be done using sockets but before doing this, I would like to be sure that it is not possible to use telnet with popen. I did not find something clear on the web yet.
Here is an example of the code I would like to use:
#include <stropts.h>
#include <stdio.h>
#include <unistd.h>
int main ( int argc, char** argv)
{
printf("Open a network client\n");
FILE* pipe = popen("telnet\n", "r");
sleep(1);
printf("File number %d\n", fileno(pipe));
printf("ioctl: is a good pipe ? =%d\n", ioctl(fileno(pipe), I_CANPUT,0));
printf("isastream: is a good pipe ? =%d\n", isastream(fileno(pipe)));
return 0;
}
And the associated makefile:
all:
g++ main.cpp -o test
clean:
rm test