用C返回系统()的值 [英] return value of system() in C

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

问题描述

我使用系统()命令用C来执行,如SC查询MySQL的或NET START MySQL的命令
如果参数为空指针则返回1,如果CMD处理器确定otherwie 0。
成功的命令执行一样,如果它执行SC查询MySQL的则返回0。

i am using system() command in C to execute commands like 'sc query mysql' or 'net start mysql' if parameter is null pointer then it returns 1 if cmd processor OK otherwie 0. on successful command execution like if it executes 'sc query mysql' it returns 0.

我的问题是可以,我得到它的返回值的列表?像什么它将返回如果命令无效或将在什么执行失败的返回值?我想这样做取决于系统的返回值()。

My question is can I get a list of its return value ? like what it will return if the command is invalid or what will be the return value on unsuccessful execution ? I want to do different things depending on the return value of system().

推荐答案

由于文档
国家制度()的返回 1 如果在创建新的进程要执行的命令失败,否则返回执行的命令的退出code。这是你可以检索使用回声$相同的值?在UNIX或回声%ERRORLEVEL%执行后在Windows在外壳相同的命令。所以,如果你要处理的返回值,你不得不看的命令执行什么样的回报。

As the docs state system() return -1 if creating the new process for the command to be executed fails, otherwise it returns the exit code of the command executed. this is the same value you can retrieve using echo $? in unix or echo %ERRORLEVEL% in windows after executing the same command in a shell. So if you want to handle the return values you have to look at what the commands executed return.

这篇关于用C返回系统()的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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