是用C的popen()和系统()之间的差 [英] what is the difference between popen() and system() in C

查看:164
本文介绍了是用C的popen()和系统()之间的差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的C code内执行的二进制。这是更好地执行? popen()完成或系统()

I want to execute a binary within my C code. Which is better to execute with? popen() or system()

修改:我尝试使用制度,但在执行的过程中,似乎陷入到底,不回我code。

EDIT: I tried to use system, but the process executing seems to get stuck in the end and does not return to my code.

这是做什么有什么建议?

Any suggestions on what to do?

感谢

推荐答案

的popen()为您提供了对过程的输入或输出文件流控制。 系统()没有。如果你不需要访问过程的I / O,您可以使用系统()为简单。

popen() gives you control over the process's input or output file streams. system() doesn't. If you don't need to access the process's I/O, you can use system() for simplicity.

系统()是C89和C99; 的popen()与POSIX只(虽然Windows的API也有一个)。

system() is in C89 and C99; popen() is Posix only (though the Windows API also has one).

这两个函数调用某种形式的的的执行命令(例如 / bin / sh的在Linux上,大概 CMD.EXE 在Windows上)。如果你想直接执行可执行文件,你是在POSIX,你也可以看看 EXEC * 在功能一起选择叉 - 家庭()(因为执行exec()替换的当前进程)。

Both functions invoke some form of a shell to execute the command (e.g. /bin/sh on Linux, and probably cmd.exe on Windows). If you want to execute an executable file directly and you are on Posix, you can also look at the exec*-family of functions in conjuction with fork() (since exec() replaces the current process).

这篇关于是用C的popen()和系统()之间的差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆