检查C shell命令,返回值 [英] Check shell command return value in c
本文介绍了检查C shell命令,返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道我怎么可以做这样的事情在C程序。
如果wget的-q www.someurl.com;
然后回显OK;
别的不呼应那里;
科幻
解决方案
- 从父做
叉()
。 - 按1 DO
创建的子里面EXEC *()
。 - 从父母或信号处理程序听
SIGCHLD
做的等待(安培;状态)。
- 最后使用
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
解决方案
- From the parent do
fork()
. - Inside the child created by 1. do
exec*()
. - From the parent or a signal handler listening to
SIGCHLD
dowait(&status)
. - Finally use
WEXITSTATUS(status)
to get the equivalent tor=$?
from your script.
这篇关于检查C shell命令,返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文