在命令窗口中从WindowsForms应用程序获取退出代码 [英] Get Exitcodes from WindowsForms Application in command window

查看:77
本文介绍了在命令窗口中从WindowsForms应用程序获取退出代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从命令promt启动Windows Forms应用程序,我需要获取Windows Forms应用程序生成的退出代码。命令promt启动应用程序并立即返回。但是应用程序在后台执行。有办法获取退出代码吗?

I'm starting a Windows Forms application from the command promt and I need to get the exit codes that the windows forms application generates. The command promt starts the application and returns immediatly. But the application executes in the background. Is there a way to get the Exit codes?

亲切问候

基督徒。

推荐答案

答案是


start /wait [Your Command]

然后


echo %errorlevel%

提取返回值。

-

而且因为我喜欢编写批处理文件...(这是我的问题。 )

And because I like writing batch files... (it's a problem of mine...)


@echo off
echo Waiting for program to exit...
start /wait %*
echo Return code was %errorlevel%

将其保存为.bat扩展名。使用您要运行的程序的命令行作为参数运行它。它将运行您提供的命令,等待其结束,然后打印返回值。

Save it somewhere with a .bat extension. Run it with the command line of the program you want to run as it's arguments. It will run the command you gave it, wait for it to end, and then print the return value.

您还可以通过替换开始/ wait来对程序进行硬编码与您的应用程序保持一致,因为如文档(开始/?)所示:

You could also hard code the program by replacing the start /wait line with your app, because as the docs (start /?) say:


在执行32位GUI应用程序时,CMD.EXE
不会等待应用程序终止,然后再返回到
命令提示符。如果在命令脚本中执行
,则不会发生此新行为。

When executing an application that is a 32-bit GUI application, CMD.EXE does not wait for the application to terminate before returning to the command prompt. This new behavior does NOT occur if executing within a command script.

如果调用了CMD,它将等待winform。从脚本中查看是否启用了命令扩展。

CMD will wait for a winform if it is called from a script whether or not Command Extensions are enabled.

这篇关于在命令窗口中从WindowsForms应用程序获取退出代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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