从bash脚本访问ERRORLEVEL [英] accessing ERRORLEVEL from bash script

查看:255
本文介绍了从bash脚本访问ERRORLEVEL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,只叫从Windows命令提示符时正常工作。是与输入/输出流。

I have an application that only works properly when called from a windows command prompt. Something to do with the input/output streams.

所以我可以从一个bash脚本通过将其作为参数传递给CMD调用它。

So I can call it from a bash script by passing it as an argument to cmd.

CMD / Cbadapp

cmd /c "badapp"

这工作正常 - 但偶尔badapp失败并网的问题 - 我没有得到任何反馈。反正是有检查从bash脚本ERRORLEVEL的 - 或者看到运行bash脚本在终端上从badapp输出?

This works fine - but occasionally badapp fails with network problems - and I get no feedback. Is there anyway to check the ERRORLEVEl from the bash script - or see the output from badapp on the terminal running the bash script?

推荐答案

$?是包含错误级别的变量。

yes, $? is the variable that contains the error level.

尝试回声$?例如

从Cygwin的bash的一个例子(我猜你是因为你在你的榜样使用Windows CMD 使用Cygwin。)

An example from Cygwin bash (I'm guessing you are using Cygwin because you are using the Windows cmd in your example.)

susam@nifty /cygdrive/c/Documents and Settings/susam/Desktop
$ cmd /c "badapp"
'badapp' is not recognized as an internal or external command,
operable program or batch file.

susam@nifty/cygdrive/c/Documents and Settings/susam/Desktop
$ if [ $? -eq 0 ]
> then
>   echo "good"
> else
>   echo "bad"
> fi
bad

这篇关于从bash脚本访问ERRORLEVEL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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