从libexpect获取输出
Get output from libexpect
我正在尝试通过libexpect输入命令产生的输出,我不太擅长C风格的做事方式,我不确定如何继续。
问题是,虽然这是python用户的一个流行程序,但我只能找到一些在C/c++中使用libeexpect的基本示例,并且似乎没有提到获取输出。
示例程序:
// 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;
}
虽然这部分工作,但它无法获得第一个字符。
实际上,SO在我发布正确答案后右侧显示了一个链接,我想我没有看得足够努力:
#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;
}
(取自如何从linux上c++中使用libeexpect创建的文件*中读取标准输出?)
相关文章:
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 我无法获取以下代码的输出
- 从C++应用获取PowerShell脚本输出
- 我无法从 C# 获取 PInvoke 的输入参数以C++ DLL 以用作 IntPtr 的输出
- 我需要帮助在一个类中输入两个字符串并获取其输出
- 使用提升过程获取 shell 命令的标准输出
- 从 exprTk 获取向量作为输出
- 如何使用 c++ libboost 运行进程并获取其输出?
- 从用户获取输入/输出
- 从 c++ 中的实例化进程获取输出的可靠方法是什么?
- 如何在C++中执行命令并获取命令的返回代码标准输出和标准
- TFLite 隔离错误,通过获取C++输入和输出
- 在集成终端上运行vscode lldb调试器时,如何获取程序的输出?
- 使用 boost::regex 从目录中获取带有一些正则表达式的文件名称时出现意外输出
- 使用 qt 或 c++ 从桌面获取输入和输出
- 如何从amd gpus的显示输出中获取图像数据
- 获取使用p4api运行的Perforce命令的输出
- 获取C++输出流中元素的大小
- 如何从进程获取实时、非阻塞输出
- 异步输入和输出/获取前缀后的输入