c++ - Get output from libexpect -
i trying output produced command entered through libexpect, not skilled @ c style of doing things, , i'm not sure how proceed.
the problem seems while popular program python users, can find few basic examples of using libexpect in c/c++ , none seem mention getting output.
example program:
// g++ t.cpp -lexpect -ltcl -o t #include <iostream> #include <tcl8.5/expect.h> int main(){ file *echo = exp_popen(const_cast<char *>("telnet google.com 80")); std::cout << char(fgetc(echo)) << std::endl; std::cout << std::string(80, '=') << std::endl; char c; do{ c = fgetc(echo); std::cout << "'" << c << "'"; }while(c != eof); return 0; }
while partially works, fails first character.
actually, showed link on side right after posted showing correct answer, guess did not hard enough:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <tcl8.5/expect.h> #include <errno.h> int main() { char str[512]; file *f = exp_popen("ssh user@mybox ls -lr"); if (f==null) { printf("failed (%s)\n", strerror(errno)); return 1; } while(fgets(str, sizeof(str)-1, f)) { printf("%s", str); } return 0; }
(taken how read stdout file* created libexpect in c++ on linux?)
Comments
Post a Comment