Hi there,
I’m just having a problem to use the telnet command via popen().
If I use the attached code to telnet to a fully installed QNX 6.3.0 SP 3 there is no problem (172.16.205.6).
But if I try to use the same code to telnet to an embedded system running with QNX 6.5.0 it won’t ask for username/password (172.16.205.7).
If I use the telnet program directly from shell I can telnet to BOTH systems.
What is missing on the embedded system or what do I have do account for?
Kind regards
Martin
./myTelnet_g 172.16.205.6
telnet> Trying 172.16.205.6…
Connected to 172.16.205.6.
Escape character is ‘^]’.
login: 1
2
root
Password:
Tue Mar 15 12:09:48 2011 on /dev/ttyp2
Last login: Tue Mar 15 12:08:17 2011 on /dev/ttyp2
edit the file .profile if you want to change your environment.
To start the Photon windowing environment, type “ph”.
ls -l
total 194
drwx------ 5 root root 4096 Jan 11 09:23 .
drwxr-xr-x 18 root root 4096 Feb 04 10:09 …
-rw-rw-r-- 1 root root 51 Mar 15 12:09 .lastlogin
drwx------ 3 root root 4096 Jul 05 2007 .mozilla
drwxrwxr-x 10 root root 4096 Aug 30 2010 .ph
-rw-r–r-- 1 root root 191 May 07 2004 .profile
drwxrwxr-x 7 root root 4096 Aug 19 2010 ide4-workspace
-rw-rw-rw- 1 root root 77563 Aug 07 2007 module.code
exit
Connection closed by foreign host.
./myTelnet_g 172.16.205.7
telnet> Trying 172.16.205.7…
Connected to 172.16.205.7.
Escape character is ‘^]’.
QNX Neutrino () (ttyp0)
Connection closed by foreign host.
1
2
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
char achTelnetString[255+1];
FILE *fhTelnet = NULL;
sprintf(achTelnetString, “telnet”);
fhTelnet = popen(achTelnetString, “w”);
if(fhTelnet != NULL)
{
fprintf(fhTelnet, “open %s\n”, argv[1]);
fflush(fhTelnet);
sleep(2);
printf(“1\n”); // Just to see
sleep(2);
printf(“2\n”); // what’s going on
fprintf(fhTelnet, "root\n");
fflush(fhTelnet);
fprintf(fhTelnet, "mypassword\n");
fflush(fhTelnet);
fprintf(fhTelnet, "ls -l\n");
fflush(fhTelnet);
sleep(1);
fprintf(fhTelnet, "exit\n");
fflush(fhTelnet);
sleep(1);
pclose(fhTelnet);
fhTelnet = NULL;
}
return(0);
}