近日需要在c++中使用expect, 找了好久的资料才完成。。。贴代码
#include <tcl.h>
#include <expect.h>
#include <stdio.h>
#include <unistd.h>
#include <iostream>
#include <expect_tcl.h>
using namespace std;
int main()
{
extern int exp_timeout;
exp_timeout = 100;
Tcl_Interp *tcl;
tcl = Tcl_CreateInterp();
if (Expect_Init(tcl) != TCL_OK)
{
puts("failure");
return 1;
}
int fd = exp_spawnl("ssh","ssh","account@machine", "echo start;ls ~;",(char *)0);
if(fd <0)
{
cout<<"Fail to ssh"<<endl;
return -1;
}
int loop =1;
int result;
while(loop)
{