Maybe you could rephrase the whole question then. As it stands, the only
interpretation of "create" that really makes sense in your original post
is that your code started another process (or rather, didn't start another
process, since you wrote "didn't create").
Telling us that you didn't write the code for the other process doesn't
seem to change the overall gist of the message (there's still the
implication that your code also didn't start the other process), so it's
hard to see how we'd change the answer or verify that the answers we've
provided are still valid given that you feel you miscommunicated something
in your original post.
If you could explain more clearly what it is you're trying to do, and why
it is you think there's a possibility that either using the StandardOutput
property or named pipes might address that goal, that might help us
understand your question better.
Thanks,
Pete
What I would like to do is to get the output, input, and error from a
process I start (namely Powershell). I have tried three ways:
1. I start the process with the Process class and redirecting stdout,
stdin, and stderr using a handler to the OutputDataReceived Event, the
ErrorDataReceived Event, and a StreamWriter from the StandardInput
property. This works with cmd.exe, but powershell only return the
first two lines and the prompt appears on the regular powershell
console. The biggest down side to this way is that since I am
starting the process using a user's name and password, the process
class always starts a console for me. I really want this program to
run as a service and do not want a console shown. Plus, I don't seem
to be getting all the output and error.
2. I start the process with the win32 API call CreateProcessAsUser and
try to get the output, input, and error from a handle obtained by
creating a new AnonymousPipeServerStream for each, passing the handle
I receive from
AnonymousPipeServerStream.SafeFileHandle.DangerousGetHandle to the
start information of the process, and then try to read and write from
the AnonymousPipeServerStream.
3. I start the process with the win32 API call CreateProcessAsUser,
create a pipe for stdin, stdout, and stderr with another win32 API
call CreatePipe, and pass the SafeFileHandle received from that to a
FileStream that I try to read and write from. With this method, I can
hide the window, but as soon as I call ReadLine() on the stdout
stream, it seems to return nothing. I step through with the debugger,
and it just goes on with the rest of the code without giving me any
output. The same thing happens with way #2.
So to sum up, I can't get the redirected output and input from
powershell and I'm just grasping at straws to find something else to
try. Does that clarify things? Do you need to see some code or is
the description enough?
Thanks.