C: Run a System Command and Get Output? 在C程序中调用工具,并且得到结果。
现在在做一个WIFI API相关的库,这样就可以让其他的人管理WIFI.
在调用API的时候要回复SHELL打印的信息,比如说搜索热点,而且不在SHELL中打印出来。然后把信息返回给调用API的程序。
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char *argv[] )
{
FILE *fp;
char path[1035];
/* Open the command for reading. */
fp = popen("/bin/ls /etc/", "r");
if (fp == NULL) {
printf("Failed to run command\n" );
exit(1);
}
/* Read the output a line at a time - output it. */
while (fgets(path, sizeof(path), fp) != NULL) {
printf("%s", path);
}
/* close */
pclose(fp);
return 0;
}
You want the "popen" function. Here's an example of running the command "ls /etc" and outputing to the console.
C: Run a System Command and Get Output? 在C程序中调用工具,并且得到结果。的更多相关文章
- linux C程序中获取shell脚本输出(如获取system命令输出)
转载自 http://blog.csdn.net/hjxhjh/article/details/7909518 1. 前言 Unix 界有一句名言:“一行shell脚本胜过万行C程序”,虽然这句话有些 ...
- SUID或SGID程序中能不能用system函数
system()函数的声明和说明如下: 注意它的描述那里,system()执行一个由command参数定义的命令,通过调用/bin/sh -c命令来实现这个功能.也就是说它的逻辑是这样的! 进程调用s ...
- NET中调用存储过程(Output、Input)
NET中调用存储过程(Output.Input) .NET中调用存储过程(Output.Input) 带输入输出参数的存储过程 带输入输出参数的存储过程 create procedure itemCo ...
- 【DB2】If 'db2' is not a typo you can run the following command to lookup the package that contains the binary: command-not-found db2 bash: db2: command not found
数据库安装以后,db2报错如下: If 'db2' is not a typo you can run the following command to lookup the package that ...
- centos安装安全狗提示Need system command 'locate' to install safedog for linux的解决方法
今天为客户的centos服务器安装安全狗时提示Need system command 'locate' to install safedog for linux.Installation aborte ...
- .Net中使用com组件后发生System.ArithmeticException异常的解决办法(Message=算术运算中发生溢出或下溢。)
最近在开发一个.Net程序,其中涉及到对com组件的调用,或者第三方DLL调用, 在调用完以后如果使用一些小的测试程序继续运行,一切正常,但是在使用带有GUI的form程序,或者WPF程序中,继续执行 ...
- 在.net程序中使用System.Net.Mail来发送邮件
System.Net.Mail是微软自家提供的工具,在.net程序中可以使用该空间中的SmtpClient实例来实现邮件的发送. 使用System.Net.Mail空间与Web.config配置相配合 ...
- “System.Exception”类型的异常在 NHibernate.dll 中发生,但未在用户代码中进行处理
“System.Exception”类型的异常在 NHibernate.dll 中发生,但未在用户代码中进行处理 其他信息: OCIEnvCreate 失败,返回代码为 -,但错误消息文本不可用. 如 ...
- C#在父窗口中调用子窗口的过程(无法访问已释放的对象)异常,不存在从对象类型System.Windows.Forms.DateTimePicker到已知的托管提供程序本机类型的映射。
一:C#在父窗口中调用子窗口的过程(无法访问已释放的对象)异常 其实,这个问题与C#的垃圾回收有关.垃圾回收器管 理所有的托管对象,所有需要托管数据的.NET语言(包括 C#)都受运行库的 垃圾回收器 ...
随机推荐
- 设计模式 --迭代器模式(Iterator)
能够游走于聚合内的每一个元素,同时还可以提供多种不同的遍历方式. 基本概念: 就是提供一种方法顺序访问一个聚合对象中的各个元素,而不是暴露其内部的表示. 使用迭代器模式的优点: 遍历集合或者数 ...
- 《JS权威指南学习总结--第十一章子集和扩展》
js子集和扩展:http://www.cnblogs.com/ahthw/p/4298449.html ES6新增let和const关键字:http://www.cnblogs.com/telnetz ...
- Trouble Shooting
情况是这样的,我在写一个类似于Online-Judge的系统,用python很容易实现,编译源程序,运行程序,最后比较程序输出与标准输出得出成绩.现在有个问题,万一程序运行时崩溃,比如出现除0异常,a ...
- kettle在linux启动spoon.sh报错
org.eclipse.swt.SWTError: No more handles [gtk_init_check() failed] at org.eclipse.swt.SWT.error ...
- .Net Core 中使用Session
1.在 Startup 中 ConfigureServices 添加Session public void ConfigureServices(IServiceCollection services) ...
- 转载–移动互联网终端的touch事件,touchstart, touchend, touchmove
转载请注明: 转载自WEB前端开发(www.css119.com)-关注常见的WEB前端开发问题.最新的WEB前端开发技术(webApp开发.移动网站开发).最好的WEB前端开发工具和最全的WEB前端 ...
- js广告图片轮播
<div class="box"> <div class="box1"></div> <div class=" ...
- 关于socket客户端接收不定长数据的解决方案
#!/usr/bin/env python3.5 # -*-coding:utf8-*- """ 本实例客户端用于不断接收不定长数据,存储到变量res "&qu ...
- Just do it!!!
4月英语竞赛期中考试 5月初级程序员考试 6月英语四级考试 7月期末考试 加油吧年轻人!
- WinSnap屏幕截图 V4.5.6 官方最新版
软件名称: WinSnap屏幕截图软件语言: 多国语言授权方式: 免费试用运行环境: Win7 / Vista / Win2003 / WinXP 软件大小: 2.7MB图片预览: 软件简介:WinS ...