Ali*_*-47 9 windows shell powershell
我在 Windows 中使用 powershell 作为 shell。当我尝试启动一些在 PATH 环境变量中缺少 dll 依赖项的应用程序时,没有任何反应,powershell 只是默默地返回新的命令提示符。
有没有办法让 powershell 失败的声音更大,告诉我到底缺少什么,就像默认的 cmd shell 一样?
我也遇到了同样的问题。$LASTEXITCODE
PowerShell 将代码设置为-1073741515
( 0xC0000142
, 3221225794
) 但没有输出解释实际错误所在。通过 cmd.exe 运行它时,我会弹出如下内容:
由于找不到 some.dll,代码执行无法继续。重新安装该程序可能会解决此问题。
cygwin bash 向 stderr 输出与未找到 dll 相关的错误,如果您从 PowerShell 通过 bash 运行相同的错误,则可以看到该错误:
> & 'C:\tools\cygwin\bin\bash.exe' '-c' '"C:/Users/xxx/dir/main.exe"'
C:/Users/xxx/dir/main.exe: error while loading shared libraries: another.dll: cannot open shared object file: No such file or directory
Run Code Online (Sandbox Code Playgroud)
这也适用于 git bash:
> & 'C:\Program Files\Git\bin\bash.exe' '-c' '"C:/Users/xxx/dir/main.exe"'
C:/Users/xxx/dir/main.exe: error while loading shared libraries: another.dll: cannot open shared object file: No such file or directory
Run Code Online (Sandbox Code Playgroud)
相当不错,但总比没有好。
Dev*_*per -4
恐怕没有办法获得这些信息......但尝试阅读
\n\nPowerShell 中的错误处理简介 http://blogs.msdn.com/b/kebab/archive/2013/06/09/an-introduction-to-error-handling-in-powershell.aspx
\n\n或\n PowerShell 教程\xe2\x80\x93 Try Catch Final 和PowerShell 中的错误处理\n http://www.vexasoft.com/blogs/powershell/7255220-powershell-tutorial-try-catch-finally-and-error -powershell 中的处理
\n\nTry\n{\n $AuthorizedUsers = Get-Content \\\\ FileServer\\HRShare\\UserList.txt -ErrorAction Stop\n}\nCatch [System.OutOfMemoryException]\n{\n Restart-Computer localhost\n}\nCatch\n{\n $ErrorMessage = $_.Exception.Message\n $FailedItem = $_.Exception.ItemName\n Send-MailMessage -From ExpensesBot@MyCompany.Com -To WinAdmin@MyCompany.Com -Subject "HR File Read Failed!" -SmtpServer EXCH01.AD.MyCompany.Com -Body "We failed to read file $FailedItem. The error message was $ErrorMessage"\n Break\n}\nFinally\n{\n $Time=Get-Date\n "This script made a read attempt at $Time" | out-file c:\\logs\\ExpensesScript.log -append\n}\n
Run Code Online (Sandbox Code Playgroud)\n