检查C shell命令,返回值 [英] Check shell command return value in c

查看:180
本文介绍了检查C shell命令,返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我怎么可以做这样的事情在C程序。

 如果wget的-q www.someurl.com;
然后回显OK;
别的不呼应那里;
科幻


解决方案

  1. 从父做 叉()

  2. 按1 DO 创建的子里面EXEC *()

  3. 从父母或信号处理程序听 SIGCHLD 做的 等待(安培;状态)。

  4. 最后使用 WEXITSTATUS(状态) ,向你的脚本获得等同于 R = $?

I want to know how can I do something like this in a C program.

if wget -q www.someurl.com;
then echo OK;
else echo Not there;
fi

解决方案

  1. From the parent do fork().
  2. Inside the child created by 1. do exec*().
  3. From the parent or a signal handler listening to SIGCHLD do wait(&status).
  4. Finally use WEXITSTATUS(status) to get the equivalent to r=$? from your script.

这篇关于检查C shell命令,返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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