- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试运行外部 shell 命令并使用 C++ 的 Boost 库读取其输出,但似乎该命令未运行或我无法访问输出。我正在使用 their documentation举个例子,这样写:
#include <boost/process.hpp>
namespace bp = boost::process;
bool is_process_running(std::string p_name){
string cmd = "ps aux 2>&1";
bp::ipstream out;
std::string line;
bp::child c(cmd, bp::std_out > out);
// the while is supposed to read each line of the output
// but the execution doesn't enter here
while(c.running() && std::getline(out, line) && !line.empty())
{
if(line.find(p_name) != std::string::npos)
{
return true;
}
}
c.wait();
return false;
}
目标是验证 ps aux
的每一行输出并搜索进程是否正在运行。那么,这里可能是什么问题?或者,您能否提供一个简单的代码片段来执行此操作?
最佳答案
只需使用一个 shell(或使用 bp::system
):
#include <boost/process.hpp>
namespace bp = boost::process;
bool is_process_running(std::string p_name){
std::vector<std::string> args { "-c", "ps aux 2>&1" };
bp::ipstream out;
bp::child c(bp::search_path("sh"), args, bp::std_out > out);
for (std::string line; c.running() && std::getline(out, line);) {
if (line.find(p_name) != std::string::npos) {
return true;
}
}
c.wait();
return false;
}
#include <iostream>
int main() {
std::cout << "bogus: " << is_process_running("bogus") << "\n";
std::cout << "a.out: " << is_process_running("a.out") << "\n";
}
打印
bogus: 0
a.out: 1
关于c++ - 如何使用 C++ libboost 运行进程并获取其输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52187867/
现在我正尝试在我的项目中使用 libboost-regex。但是我有点困惑,因为下面有一些相关的库。我只想使用 boost-regex。那么在那种情况下,安装 libboost-regex 的最佳方法
我正在尝试在 Centos7 中安装 ContextBroker: sudo rpm -i contextBroker-0.14.1-1.X86_64.rpm 但是我遇到了下一个错误: error:
我正在尝试在 ASIO 中实现一个简单的客户端/服务器。 我想要服务器端的以下内容: onConnect() onDisconnect() onMessageRecieved(char* 数据) se
我已经通过apt-get安装了libboost-dev,它放在/usr/lib中。 /usr/lib$ ls | grep boost libboost_filesystem.so.1.46.1 li
我正在尝试运行外部 shell 命令并使用 C++ 的 Boost 库读取其输出,但似乎该命令未运行或我无法访问输出。我正在使用 their documentation举个例子,这样写: #inclu
我正在学习一些教程,这些教程解释了我应该添加 libboost_chrono-vc140-mt-gd-1_62.lib 作为我的程序将与之链接的库。我遇到的问题是 IDK 在 Visual Studi
我有一个 debian/control 文件,其中包括: Build-Depends: ... libboost1.35-dev, libboost-date-time1.35-dev, ... 这会
我看到以下错误 ImportError: /usr/local/lib/libboost_python.so.1.57.0: undefined symbol: PyUnicode_AsUTF8Str
我正在 Linux Mint 上重新编译一些使用 libboost 的 C++ 代码。从 Mint 18 升级到 Mint 19.3 之前,代码运行良好。从那时起,我可以编译代码,但在执行过程中,它会
我刚刚安装了 boost 1.62 并使用 --log_sink=output.xml 运行了 boost 单元测试选项,但我得到了一个错误。 这是我的命令行 ./App --log_level=te
我正在尝试在 Ubuntu 11.04 x64 上构建 32 位应用程序。由于 libboost 的链接器错误,我在构建时遇到了一些问题。构建语句中有 -lboost_system,但是当我尝试构建时
我正在尝试编译 msp430 debug stack在 OpenSUSE 上。已安装所有先决条件。当我使用静态链接选项运行它时,链接器说: _filesystem -lboost_date_time
我在我的设备中运行了 flutter 的示例代码。我得到一个日志: 2019-03-28 10:07:18.105 6794-6819/com.example.ijkplayer_example E/
在 Ubuntu 上有一个安装 boost 库的命令是这样的: sudo apt-get install libboost-all-dev 这个命令是否也安装和编译只有头文件的库? 如果没有,我还需要
我在我的项目中使用了 boost。我从这里下载了预编译的二进制文件 http://boost.teeks99.com/ 链接时我收到这样的错误: 错误 18 error LNK2005: "publi
我正在尝试使用 Ubuntu 9.04 存储库在 Ubuntu 8.10 中安装 libboost 1.38,因为它在任何 8.10 存储库中都不可用。我正在尝试通过添加以下代码行来使用 Apt-pi
我正在 Ubuntu 14.04 计算机上按照以下步骤安装 HHVM。 https://www.digitalocean.com/community/articles/how-to-install-h
有没有办法在 Ubuntu 8.10 上安装 Libboost 1.38?我存储库中的最高版本是 1.35。有人建议我可以添加一些存储库来完成此操作,但我的搜索没有产生任何结果。 我必须求助于源代码吗
我正在尝试使用 OS Raspbian Jessie 在树莓派 2 上编译 Ocelot 跟踪器。我已经从 apt 安装了 libboost1.55-dev-all 库。编译时出现多个错误:“对 `b
最近在学习boost C++库。我想用 python 调用现有的 C++ 项目。我已经使用 brew install boost 在 OSX 10.11 下安装了 boost。我的 python 版本
我是一名优秀的程序员,十分优秀!