Z
Zach
I have a batch file that executes some very complicated logic. I want
to execute this batch file programatically from a console application
I've written and have the resulting environment be part of the
original process. This seems simple -- cmd.exe does it trivially by
just typing "foo.bat". But whenever I spawn a process from my console
application, only the environment of this new process is affected by
the setting of environment variables, so I seem to be missing
something.
As an ultimate hack, I thought about spawning a new process, running
the batch file and then issuing the "SET" command via redirected
Standard Input. Then capturing the output from the parent, parsing
the resulting table by splitting on the equal sign, and using
System.Environment.* to manually construct the environment I wish.
But even that depends on me being able to use the
Process.OutputDataChanged event which either is broken, or doesn't do
what I think it does. I thought it would get called back every time
it detected new data on standard out, but this does not seem to be the
case. If I manually read standard out through Process.StandardOut.Read
(), this works but it relies on some magic harcoded text to determine
the start and endpoints of the environment block since it captures all
text of the entire console window. I was hoping OutputDataChanged
would allow me to detect only text that appeared as a result of me
issuing the SET command.
Any clever ideas on how I can make this work?
to execute this batch file programatically from a console application
I've written and have the resulting environment be part of the
original process. This seems simple -- cmd.exe does it trivially by
just typing "foo.bat". But whenever I spawn a process from my console
application, only the environment of this new process is affected by
the setting of environment variables, so I seem to be missing
something.
As an ultimate hack, I thought about spawning a new process, running
the batch file and then issuing the "SET" command via redirected
Standard Input. Then capturing the output from the parent, parsing
the resulting table by splitting on the equal sign, and using
System.Environment.* to manually construct the environment I wish.
But even that depends on me being able to use the
Process.OutputDataChanged event which either is broken, or doesn't do
what I think it does. I thought it would get called back every time
it detected new data on standard out, but this does not seem to be the
case. If I manually read standard out through Process.StandardOut.Read
(), this works but it relies on some magic harcoded text to determine
the start and endpoints of the environment block since it captures all
text of the entire console window. I was hoping OutputDataChanged
would allow me to detect only text that appeared as a result of me
issuing the SET command.
Any clever ideas on how I can make this work?