现在在做一个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程序中调用工具,并且得到结果。的更多相关文章

  1. linux C程序中获取shell脚本输出(如获取system命令输出)

    转载自 http://blog.csdn.net/hjxhjh/article/details/7909518 1. 前言 Unix 界有一句名言:“一行shell脚本胜过万行C程序”,虽然这句话有些 ...

  2. SUID或SGID程序中能不能用system函数

    system()函数的声明和说明如下: 注意它的描述那里,system()执行一个由command参数定义的命令,通过调用/bin/sh -c命令来实现这个功能.也就是说它的逻辑是这样的! 进程调用s ...

  3. NET中调用存储过程(Output、Input)

    NET中调用存储过程(Output.Input) .NET中调用存储过程(Output.Input) 带输入输出参数的存储过程 带输入输出参数的存储过程 create procedure itemCo ...

  4. 【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 ...

  5. centos安装安全狗提示Need system command 'locate' to install safedog for linux的解决方法

    今天为客户的centos服务器安装安全狗时提示Need system command 'locate' to install safedog for linux.Installation aborte ...

  6. .Net中使用com组件后发生System.ArithmeticException异常的解决办法(Message=算术运算中发生溢出或下溢。)

    最近在开发一个.Net程序,其中涉及到对com组件的调用,或者第三方DLL调用, 在调用完以后如果使用一些小的测试程序继续运行,一切正常,但是在使用带有GUI的form程序,或者WPF程序中,继续执行 ...

  7. 在.net程序中使用System.Net.Mail来发送邮件

    System.Net.Mail是微软自家提供的工具,在.net程序中可以使用该空间中的SmtpClient实例来实现邮件的发送. 使用System.Net.Mail空间与Web.config配置相配合 ...

  8. “System.Exception”类型的异常在 NHibernate.dll 中发生,但未在用户代码中进行处理

    “System.Exception”类型的异常在 NHibernate.dll 中发生,但未在用户代码中进行处理 其他信息: OCIEnvCreate 失败,返回代码为 -,但错误消息文本不可用. 如 ...

  9. C#在父窗口中调用子窗口的过程(无法访问已释放的对象)异常,不存在从对象类型System.Windows.Forms.DateTimePicker到已知的托管提供程序本机类型的映射。

    一:C#在父窗口中调用子窗口的过程(无法访问已释放的对象)异常 其实,这个问题与C#的垃圾回收有关.垃圾回收器管 理所有的托管对象,所有需要托管数据的.NET语言(包括 C#)都受运行库的 垃圾回收器 ...

随机推荐

  1. 使用PhotoShop

    详细请看:http://blog.sina.com.cn/s/blog_73dc36510101ahim.html

  2. 3-jQuery - AJAX get()

    介绍 GET 基本上用于从服务器获得(取回)数据.注释:GET 方法可能返回缓存数据. 格式 $.get(URL,callback); //必需的 URL 参数规定您希望请求的 URL. //可选的 ...

  3. (负)-margin在页面布局中的应用

    有关margin的原理可以看看这篇文章:http://www.cnblogs.com/2050/archive/2012/08/13/2636467.html#2457812 有关margin负值的几 ...

  4. luci小记

    LuCI使用controller目录下的lua脚本中的index函数来构造了一个dispatch树.cgi环境变量PATH_INFO会被用在dispatch树种,例如 cgi-bin/luci/foo ...

  5. setsockopt()用法(参数详细说明)(转)

    nt setsockopt(SOCKET s,int level,int optname,const char* optval,int optlen); s(套接字): 指向一个打开的套接口描述字le ...

  6. P2P直连?经服务器中转?

    当同一个系统的两个客户端A.B相互发送消息给对方时,如果它们之间存在P2P通道,那么消息传送的路径就有两种:直接经P2P通道传送.或者经服务器中转.如下图所示: 通常就一般应用而言,如果P2P通道能够 ...

  7. Openjudge-计算概论(A)-大象喝水

    描述 一只大象口渴了,要喝20升水才能解渴,但现在只有一个深h厘米,底面半径为r厘米的小圆桶(h和r都是整数).问大象至少要喝多少桶水才会解渴. 输入输入有一行:包行两个整数,以一个空格分开,分别表示 ...

  8. AS3.0杂记——Dictionary、Object与Array

    来源:http://blog.csdn.net/m_leonwang/article/details/8811829 Object.Array与Dictionary都是关联数组,就是用“键”来索引存储 ...

  9. python 实现excel转化成json文件

    1.准备工作 python 2.7 安装 安装xlrd -- pip install xlrd 2. 直接上代码 import xlrd from collections import Ordered ...

  10. 项目管理实践【六】自动同步数据库【Using Visual Studio with Source Control System to synchronize database automatically】

    在上一篇项目管理实践[五]自动编译和发布网站中,我们讲解了如何使用MSBuild+Robocopy+WebDeployment来自动编译和部署网站,今天,我们来看一下,如何使用MSBuild +SVN ...