I'm running a comman开发者_高级运维dline process via C# System.Diagnostics.Process.
When I enter this same command in cmd.exe, it immediately prompts me for a password. After I type in the password, the process continues to completion.
However, using System.Diagnotic.Process, none of the standard output I'm redirecting ever produces a password prompt. If it did, I would programmatically enter it using the redirected standard input's WriteLine method.
Is it usual to not see prompts in the output using the Process object? Are prompts different from other standard output lines? If so, how can bring "prompt-events" into my application, enter input, and then have the process proceed the same way it does in cmd.exe?
When you redirect the output of a program written in C/C++, the stdout stream switches to buffered mode. The prompt is there, it just never got flushed from the internal buffer to the stream because the buffer didn't get filled to capacity. Just writing the password is likely to solve your problem.
When preparing the ProcessStartInfo
for your Process.Start
call, be sure to properly set the following properties:
RedirectStandardInput
RedirectStandardOutput
RedirectStandardError
And after creating your Process
object make sure to use the following properties for the appropriate redirected streams:
StandardInput
StandardOutput
StandardError
精彩评论