流程会跳过输入吗

流程会跳过输入吗

本文介绍了C#流程会跳过输入吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在使用Unrar时遇到了问题(称为C#进程).
(我知道C#有几种实现,但是大多数实现都是错误的,或者没有我需要的功能.)

一旦我重定向了标准流之一,Unrar就会跳过所有输入(例如密码请求)并退出.但是我想通过(重定向的)标准输入流(p.StandardInput.Write ...)提供这些信息!

有什么问题吗?

来源(简体):

Hi
I''ve a problem with Unrar (called as C# process).
(I know there are several implementations for C#, but the most of them are buggy or they haven''t the functions I need.)

As soon as I redirect one of the standard streams, Unrar skips all inputs (like passwort requests) and exits. But I want to provide these informations over the (redirected) standart input stream (p.StandardInput.Write ...)!

What''s the Problem?

Source (Simplyfied):

Process p = new Process();
p.StartInfo.FileName = "UnRAR.exe";
p.EnableRaisingEvents = true;
p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived);
p.ErrorDataReceived += new DataReceivedEventHandler(p_ErrorDataReceived);

//p.StartInfo.CreateNoWindow = true;
p.StartInfo.Arguments = "l abc.rar";
//List Archive (Filenames encrypted -> Password needed on opening)
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.Start();
p.BeginOutputReadLine();
p.BeginErrorReadLine();

p.WaitForExit();

...

void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
    Console.WriteLine(e.Data);
}



更新:
控制台显示以下内容:



UPDATE:
The Console shows the following:

UNRAR 4.10 freeware      Copyright (c) 1993-2012 Alexander Roshal

Enter password (will not be echoed) for abc.rar:

Archive abc.rar
  0 files


CRC failed in the encrypted file abc.rar. Corrupt file or wrong password.


但是,正如您在我的源代码中看到的那样,我没有向该进程发送任何内容(因此它应在输入密码"之后等待)
似乎该过程只是跳过了所有getch(或readLine())命令,并使用一个空字符串继续.

感谢您的回答.


But as you see in my source I haven''t send anything to the process (so it should wait after "Enter password" )
It seems as the process simply skips all the getch (or readLine()) commands and takes an empty string to continue.

Thanks for your answers.

推荐答案

p.StartInfo.RedirectStandardInput = true;



您是否尝试过将其设置为false?


更新:

http://msdn.microsoft.com/en-us/library/system. diagnostics.processstartinfo.redirectstandardinput.aspx [ ^ ]

按照此处的示例,您是否在代码中的任何位置执行此操作?



Have you tried setting to false?


Update:

http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandardinput.aspx[^]

Following the example here, are you doing this anywhere in your code?

StreamWriter myStreamWriter = myProcess.StandardInput;
// Write each line to the StandardInput stream of the command.
string inputText;
myStreamWriter.WriteLine(inputText);



这篇关于C#流程会跳过输入吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 11:04