gpt4 book ai didi

c++ - 使用单独的参数调用 `execve failed: No such file or directory` 时获取 `boost::process::system()`

转载 作者:行者123 更新时间:2023-11-28 04:07:05 26 4
gpt4 key购买 nike

如果我用一个完整的硬编码命令调用它,它会工作,但是当我分开参数时,它会抛出:

execve failed: No such file or directory

运行示例 here :

bp::system("grep -c false /etc/passwd"); // ok
bp::system("grep", "-c", "false", "/etc/passwd"); // fails

bp::system(cmd="grep -c false /etc/passwd"); // ok
bp::system(exe="grep", args={"-c", "false", "/etc/passwd"}); // fails

最佳答案

显然,在使用 exe-args 样式 时,它不会检查 PATH:

If a single string (or the explicit form bp::cmd), it will be interpreted as a command line. That will cause the execution function to search the PATH variable to find the executable. The alternative is the exe-args style, where the first string will be interpreted as a filename (including the path), and the rest as arguments passed to said function.

它适用于完整路径:

bp::system("/bin/grep", "-c", "false", "/etc/passwd");

关于c++ - 使用单独的参数调用 `execve failed: No such file or directory` 时获取 `boost::process::system()`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58537026/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com