簡體   English   中英

如何從C#代碼讀取Powershell腳本的退出代碼

[英]How to read exit code of powershell script from C# code

我想從C#代碼執行以下Power Shell腳本

Add-Content D:\f.txt "Import Module"
Add-Content D:\f.txt "Remove Module"
Add-Content D:\f.txt "The End"
exit 4

我可以從C#代碼成功執行腳本。

我希望我的C#程序讀取Powershell返回的退出值(即4)。

您能告訴我如何實現嗎? 注意:我是C#和powershell的新手。

如何通過c#讀取PowerShell退出代碼相同的問題,似乎您需要嘗試其他方法,例如PowerShell.Streams.Error或Runspace.RunspaceStateInfo,而不是退出代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM