相关疑难解决方法(0)

如何在.NET中指定控制台应用程序的退出代码?

我在.NET中有一个简单的控制台应用程序.它只是更大应用程序的测试部分.我想指定我的控制台应用程序的"退出代码".我该怎么做呢?

.net c# exit-code

457
推荐指数
10
解决办法
30万
查看次数

使用Start-Process和WaitForExit而不是-Wait获取ExitCode

我正在尝试从PowerShell运行程序,等待退出,然后访问ExitCode,但我没有太多运气.我不希望使用-WaitStart-Process,因为我需要一些处理在后台进行.

这是一个简化的测试脚本:

cd "C:\Windows"

# ExitCode is available when using -Wait...
Write-Host "Starting Notepad with -Wait - return code will be available"
$process = (Start-Process -FilePath "notepad.exe" -PassThru -Wait)
Write-Host "Process finished with return code: " $process.ExitCode

# ExitCode is not available when waiting separately
Write-Host "Starting Notepad without -Wait - return code will NOT be available"
$process = (Start-Process -FilePath "notepad.exe" -PassThru)
$process.WaitForExit()
Write-Host "Process exit code should be here: " $process.ExitCode
Run Code Online (Sandbox Code Playgroud)

运行此脚本将导致启动记事本.手动关闭后,将打印退出代码,它将重新开始,不使用 …

powershell powershell-2.0

61
推荐指数
5
解决办法
11万
查看次数

标签 统计

.net ×1

c# ×1

exit-code ×1

powershell ×1

powershell-2.0 ×1