3

I have a batch script that sets up some environment variables and then sets up a new cmd.exe within the currently executing cmd.exe.

Example of what the batch script looks like:

setlocal set foo=bar cmd.exe 

How do I start a new Process() object that calls this batch script, then is able to pipe the StandardInput into the new instance of the cmd.exe?

This is my current code that doesn't work:

ProcessStartInfo procStartInfo = new ProcessStartInfo(); procStartInfo.FileName = @"C:\path\to\test.bat"; using (Process proc = Process.Start(procStartInfo)) { proc.StandardInput.WriteLine("echo %foo%"); // InvalidOperationException } 

1 Answer 1

1

You have to use ProcessStartInfo class and set RedirectStandardInput flag, and then provide a stream that you will supply data with.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.