在C程序中执行一个Linux命令 [英] Execute a Linux command in the c program

查看:334
本文介绍了在C程序中执行一个Linux命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用系统的系统调用C程序执行Linux命令,但不希望它倾倒在终端上的输出或错误日志。我该怎么办?是否有任何其他方式做到这一点?

I am trying to execute a Linux command in c program using system system call, but the don't want it to dump the output or error logs on the terminal. What should I do? Is there any other way to do this?

推荐答案

由于系统()调用使用shell执行命令,可以输出和错误重定向到/ dev / null的,例如

As the system() call uses a shell to execute the command, you can redirect stdout and stderr to /dev/null, e.g.

system("ls -lh >/dev/null 2>&1");

这篇关于在C程序中执行一个Linux命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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