0

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 (i.e. 4) returned from the powershell.

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

2
  • 7
    Please show us the C# code how you execute the script. The Powershell code itself is not much of interest for answering your question. Commented Oct 29, 2012 at 7:30
  • possible duplicate of How to read PowerShell exit code via c# Commented Oct 29, 2012 at 16:25

1 Answer 1

0

same probleam as How to read PowerShell exit code via c#, it seems that you need to try alternative approach like PowerShell.Streams.Error or Runspace.RunspaceStateInfo rather than exit code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.