简体   繁体   中英

How to read exit code of powershell script from C# code

I want to execute following power shell script from C# code

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

I can execute the script from the C# code successfully.

I want my C# program to read the exit value (ie 4) returned from the powershell.

Can you please let me know how I can achieve it? Note: I am new to C# and powershell.

如何通过c#读取PowerShell退出代码相同的问题,似乎您需要尝试其他方法,例如PowerShell.Streams.Error或Runspace.RunspaceStateInfo,而不是退出代码。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM