You are not logged in.
Pages: 1
#include <stdio.h>
#include <expect.h>
// gcc -lexpect5.32 -ltcl8.3 -lm -o x test.c
int main(){
FILE *fp1;
int ec;
char buff[128];
exp_loguser = 1;
exp_timeout = 3600;
if (0 == (fp1 = exp_popen("gdb"))) {
printf("exp_popen failed\n");
exit(-1);
}
while(1){
if (0 > exp_fexpectl(fp1,exp_glob,"(gdb)",0,exp_end)) exit(-1);
fgets(buff, sizeof(buff), stdin);
fprintf(fp1,"%s", buff);
}
return(0);
}
Offline
1. Well, I've never used libexpect, but taking a quick look at the
man pages and header files, try adding this:
exp_stty_init = "-echo";
2. I'm guessing probably because you have no "*.a" static version
of libexpect (or, one of the other libs you link against) installed...
Offline
Well, CTRL-D generally doesn't generate a signal... Typically,
it merely simulates EOF... Ie: if you're manually typing in input to
some command, you can make it believe it has reached end of
file by hitting CTRL-D...
As for the other problem, I have no idea what library openpty() is
supposed to be in, but you just need to find it (and, hope it has a
"*.a" static version), and then just link it in as well...
Oh, hell, I just decided to search through my various system
libs, and I found openpty() in "libutil"... So, try throwing "-lutil" into
your command-line, or if that doesn't work, hunt around your
system for "libutil.a" (or similar), and pass that to gcc, as well...
Offline
All I did was a simple for loop through various libs, printing them
and passing them to "nm | grep", as well... The "find" approach
is just as good, if not easier...
It sounds like the pty isn't getting initialized properly, or something...
Are "exp_ttycopy" and "exp_ttyinit" set to 1? Maybe throw "sane"
into the "exp_stty_init" options, as well? *shrug*
Offline
char ch;
struct termios old, new;
exp_loguser = 1;
exp_timeout = 3600;
//exp_stty_init = "-echo";
exp_ttyinit = 1;
exp_ttycopy = 1;
hnd = exp_popen(sh);
while(1){
if (0 > exp_fexpectl(hnd, exp_glob, "$" , 0, exp_end)) exit(1);
tcgetattr (0, &old);
memcpy (&new, &old, sizeof (struct termios));
new.c_lflag &= ~(ICANON | ECHO);
tcsetattr (0, TCSANOW, &new);
read (0, &ch, 1);
write(fileno(hnd), &ch, 1);
tcsetattr (0, TCSANOW, &old);
fflush(hnd);
}
Offline
Yeah, the problem is you do exp_fexpectl() after every single char
of input, looking for a new shell prompt, which isn't going to come...
Why do you do that exp_fexpectl(), anyway?? Why not simply
just read as much data as it has to give you, and output it? Or,
if you really want to use exp_fexpectl(), why not simply call it
without the search for "$", and with "exp_timeout" set to 0, so it
just reads as much as it can without blocking? (Technically, you
should use select() on 0 (stdin) and the expect FD, and whenever
either one has data to read, read it and then send it to the other...)
And, there's no point in constantly switching back and forth between
canonical input mode and non... Just set it to raw mode outside
the loop at the top, and restore outside at the bottom...
Offline
Pages: 1