如果发生错误,在 Windows 控制台中暂停 GNU Make
我负责的应用程序的部分安装编译了一些 C 代码库。 这是使用 GNU Make 在控制台中完成的。
因此,作为安装的一部分,控制台窗口会弹出,您可以在编译和链接时看到 make 文件输出向导,完成后控制台窗口关闭并且安装程序继续。
一切都很好,除非出现编译错误。 然后,在您有机会弄清楚发生了什么之前,make 文件就会出错并且控制台窗口会关闭。
因此,如果 makefile 出现错误,我希望控制台窗口暂停并具有“按某个键继续”类型的功能,以便控制台保持打开状态。 否则,只需正常退出并关闭控制台即可。
我不知道如何在 GNU Makefile 或可以运行 Make 的批处理文件中执行此操作。
Part of the install for an app I am responsible for, compiles some C code libraries. This is done in a console using GNU Make.
So, as part of the install, a console window pops open, you see the make file output wiz by as it compiles and links, when finished the console window closes and the installer continues.
All good, unless there is a compilation error. Then the make file bugs out and the console window closes before you have a chance to figure out what is happening.
So, what I'd like to happen is have the console window pause with a 'press a key to continue' type functionality, if there is an error from the makefile so that the console stays open. Otherwise, just exit as normal and close the console.
I can't work out how to do this in a GNU Makefile or from a batch file that could run the Make.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您尝试过“暂停”命令吗?
Have you tried the 'pause' command?
使用这个简单的 C 程序来操作退出代码:
我们可以在批处理文件中测试退出代码,如下所示:
条件:
0 => 0 == TRUE
当
ERRORLEVEL = 0
时,会发生暂停,因为逻辑是>=
或大于或等于< /强>。 这很重要,因为目前还不清楚条件不是==
比较。请注意,替换
1 =>; 0
也将为 true,因此也会发生暂停。 对于任何正数都是如此。我们只能通过低于
0
:Condition:
-1 =>; 来触发相反的效果。 0 == FALSE
由于
ERRORLEVEL
为1
通常意味着存在错误,而0
没有错误,因此我们可以增加比较条件中的最小值以获得我们想要的结果,如下所示:Condition:
-1 =>; 1 == FALSE
条件:
0 => 1 == FALSE
条件:
1 => 1 == TRUE
在此示例中。 当
ERRORLEVEL
为1
或更高时,脚本将暂停。请注意,这允许
-1
退出代码与0
相同。 如果只想0
不暂停怎么办? 我们可以使用单独的语法:条件:
-1 != 0 == TRUE
条件:
0 != 0 == FALSE
条件:
1 != 0 == TRUE
在此示例中,如果
%ERRORLEVEL%
不是,脚本将暂停0
我们可以通过使用 EQU 运算符首先检查是否%ERRORLEVEL% EQU 0
来实现这一点,然后使用 NOT 运算符来获得相反的效果,相当于!=< /代码> 运算符。 然而,我相信这只适用于 NT 机器,而不适用于普通的 DOS。
参考文献:
http:// chrisoldwood.blogspot.ca/2013/11/if-errorlevel-1-vs-if-errorlevel-neq-0.html
http://ss64.com/nt/errorlevel.html
Using this simple C program to manipulate the exit code:
We can test the exit code in a batch file like so:
Condition:
0 => 0 == TRUE
When
ERRORLEVEL = 0
, the pause will occur because the logic is>=
or greater-than-or-equal. This is important, as it's not immediately clear that the condition is not a==
comparison.Notice that subsituting for
1 => 0
will also be true, and thus the pause will occur as well. This is true for any positive number.We can trigger the opposite effect only by going below
0
:Condition:
-1 => 0 == FALSE
Since an
ERRORLEVEL
of1
typically means there is an error, and0
no error, we can just increase the minimum in the comparison condition to get what we want like so:Condition:
-1 => 1 == FALSE
Condition:
0 => 1 == FALSE
Condition:
1 => 1 == TRUE
In this example. the script will pause when
ERRORLEVEL
is1
or higherNotice that this allows
-1
exit codes the same as0
. What if one only wants0
to not pause? We can use a separate syntax:Condition:
-1 != 0 == TRUE
Condition:
0 != 0 == FALSE
Condition:
1 != 0 == TRUE
In this example, the script pauses if
%ERRORLEVEL%
is not0
We can do this by using the EQU operator to first check if%ERRORLEVEL% EQU 0
, then the NOT operator to get the opposite effect, equivalent to the!=
operator. However, I believe this only works on NT machines, not plain DOS.References:
http://chrisoldwood.blogspot.ca/2013/11/if-errorlevel-1-vs-if-errorlevel-neq-0.html
http://ss64.com/nt/errorlevel.html
这就是您要查找的内容:
如果您键入,
您会得到以下信息:ERRORLEVEL number |
如果最后一个程序运行返回的退出代码等于或大于指定的数字,则指定为真条件。
This is what you're looking for:
If you type
you get this info: ERRORLEVEL number |
Specifies a true condition if the last program run returned an exit code equal to or greater than the number specified.
这应该可以解决问题:
在 DOS 中输入
help if
以获取有关错误级别用法的更多信息。this should do the trick:
type
help if
in DOS for more info on errorlevel usage.