c++ - 如何判断 popen() 是否成功?

标签 c++ c shell popen

你怎么知道 popen() 是成功/完成运行 shell 还是失败?

最佳答案

popen return value :

Upon successful completion, popen() shall return a pointer to an open stream that can be used to read or write to the pipe. Otherwise, it shall return a null pointer and may set errno to indicate the error.

fp = popen("ls *", "r");
if (fp == NULL)
    /* Handle error */;

关于c++ - 如何判断 popen() 是否成功?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8582142/

相关文章:

c - localtime() 弄错了,说 date = September 31

linux - Shell 脚本 CentOS - 通过读取它的配置文件并获取端口来终止进程

c++ - GLuint64 的平台独立 printf 格式?

c++ - 编译 LLVM IR 时使用 LLVM 头文件

c++ - 省略号函数参数的字节大小

c - 推荐保留预处理器指令的 C 前端

linux - 在 linux 上完成密码字段 scp 命令

bash - 如何以安全的方式调用 "EDITOR"环境变量来打开/编辑文件?

c++ - 冒泡排序问题 C++

c++ - 在 vector 结构中显示 vector 结构