我对从cmd.exe调用运行时从PowerShell返回退出代码值有疑问。我发现
https://weblogs.asp.net/soever/returning-an-exit-code-from-a-powershell-script
function ExitWithCode { param($exitcode) $host.SetShouldExit($exitcode) exit }
生成:
ExitWithCode : The term 'ExitWithCode' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At C:\src\t\e\exit5.ps1:6 char:1
+ ExitWithCode -exitcode 12345
+ ~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (ExitWithCode:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
但是,把“出口”放在一条新线上是可行的。这只是语言异常吗?
function ExitWithCode { param($exitcode) $host.SetShouldExit($exitcode)
exit }
还有,这个页面是2010年的,现在还是这样吗?现在有更好/更简单的方法吗?