现在在做一个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. 湖南多校对抗赛(2015.05.03)Problem B: War

    并查集.从后往前加边. #include<stdio.h> #include<string.h> #include<math.h> #include<algo ...

  2. Python编码问题整理【转】

    认识常见编码 GB2312是中国规定的汉字编码,也可以说是简体中文的字符集编码 GBK 是 GB2312的扩展 ,除了兼容GB2312外,它还能显示繁体中文,还有日文的假名 cp936:中文本地系统是 ...

  3. HDU 1874 畅通工程续(初涉dijkstra算法实现)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1874 dijkstra算法实现可参照此博客学习:http://www.cnblogs.com/biye ...

  4. 删除putty的session 以及 putty的颜色设置值

    HKEY_CURRENT_USER\Software\SimonTatham\PuTTY 将sessions里面的内容清空即可 ==================================== ...

  5. 理解php的opcode

    Opcode是一种PHP脚本编译后的中间语言,就像Java的ByteCode,或者.NET的MSL,举个例子,比如你写下了如下的PHP代码: <?php echo "Hello Wor ...

  6. 关于NLog的target和Layout

    这个没啥好说的,都是用别人的东西,看文档就行了,写的很详细. https://github.com/NLog/NLog/wiki/Configuration-file https://github.c ...

  7. C库 - 常用文件IO函数

    #include<stdio.h> 0. 文件打开关闭FILE *fp = fopen("C:\\a.dat","wb+");fclose(fp); ...

  8. amazeui tab 监听当前选项

    $('#contenttab').find('a').on('opened.tabs.amui', function(e) { if(e.target.pathname.indexOf("[ ...

  9. python 信用卡系统+购物商城见解

    通过完成信用卡系统+购物商城 使自己在利用 字典和列表方面有了较大的提升,感悟很深, 下面将我对此次作业所展示的重点列表如下: #!/usr/bin/env python3.5 # -*-coding ...

  10. java实现UDP聊天---转载

    import java.io.*; import java.net.*; class Send implements Runnable { private DatagramSocket ds; pub ...