从C++执行 bash 脚本并读取其输出 ubuntu sdk
Executing bash script from C++ and read its output ubuntu sdk
我有一个 ubuntu 应用程序,我正在尝试从中执行 bash 脚本,但它似乎不起作用。我尝试使用 system() 执行此操作
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
// tried both
system("./script.sh");
// system ("script.sh")
}
另外,我尝试对此进行研究,但没有找到解决方案; 是否可以读取输出并在文本框中显示。
使用 popen()
。
FILE *script;
char line[LINESIZE];
script = popen("./script.sh", "r");
while (fgets(line, sizeof(line), script)) {
...
}
pclose(script);
运行脚本无关紧要。这将适用于任何 shell 命令。
对于任何希望在QT中执行此操作的人,这是我所做的:
QProcess proc;
proc.start("gnome-terminal", QIODevice::ReadWrite);
if (proc.waitForStarted() == false) {
qDebug() << "Error starting terminal process";
qDebug() << proc.errorString();
return (-1);
}
相关文章:
- 递归函数计算序列中的平方和(并输出过程)
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 在Ubuntu 16.04上安装Cilk时出现问题
- 请解释"函数1(p1,p2,p3);"的输出
- C++:将控制台输出存储在宏中更好吗
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 为什么我的代码在输出中增加了93天
- 如何从void函数输出字符串
- 输入到文件并输出到另一个文件,并将流文件传递给函数
- AES加密到解密未正确输出
- 如何将c++程序的一些输出传递给shell,以便在shell中使用
- Linux Ubuntu 中的文件内输出 unicode 符号
- openssl散列产生部分不同的输出-c++ubuntu
- 从C++执行 bash 脚本并读取其输出 ubuntu sdk
- 从 Ubuntu 中的 Qt GUI 应用程序运行多个命令行应用程序并获取控制台输出
- Ubuntu 终端中字符串末尾的奇怪输出
- 将命令行输出打印到Linux(Ubuntu)的文本文件中
- 通过 Ubuntu 上的 C++ system() 将输出与 SIPp 远程命令混淆
- Tensorflow会话.Run在Android设备上运行时给出空输出张量,但在Ubuntu上运行时工作良好