> Sorry guys. When I said create, I meant wrote the code for, or
> developed in house, not spawned or forked. So I gather from the
> comments, the best bet is still to use the StandardOut property.
On Mar 25, 12:50 am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
> > Sorry guys. When I said create, I meant wrote the code for, or
> > developed in house, not spawned or forked. So I gather from the
[quoted text clipped - 19 lines]
> 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.
Peter Duniho - 26 Mar 2008 07:38 GMT
> [...]
> 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?
Your description does clarify things quite a lot, thanks. Unfortunately,
between the fact that you're trying to manage PowerShell and having
problems specific to it, and the fact that you're trying to run this as a
service and possibly having problems specific to that as well, what you're
trying to do is outside my own experience.
Ultimately, if someone is going to be able to help you, you probably will
have to post a concise-but-complete code sample that reliably demonstrates
the problem. But I hesitate to ask for it myself, since if I were able to
answer the question at all, it would involve a fair amount of time on my
part just getting oriented with respect to what you're doing.
I think that some of the other people here to know more about the specific
kinds of things you're doing though, and hopefully at least one will not
only notice the thread but also have time to address it.
Sorry I couldn't offer more specific advice. However, I'll at least take
credit for soliciting a more descriptive problem statement. :)
Pete
ghandi - 26 Mar 2008 22:53 GMT
On Mar 26, 12:38 am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
> > [...]
> > So to sum up, I can't get the redirected output and input from
[quoted text clipped - 22 lines]
>
> Pete
Thanks for the response. I'll try to come up with some complete-but-
concise code for this. That might take a bit.
Thanks again for the time.