Click here to Skip to main content
12,827,807 members (46,264 online)
Rate this:
Please Sign up or sign in to vote.

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;



void p_OutputDataReceived(object sender, DataReceivedEventArgs e)

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.

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.
Posted 24-Feb-12 9:37am
Updated 24-Feb-12 10:19am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I think you should reconsider why you are doing this then:

p.StartInfo.RedirectStandardInput = true;

Have you tried setting to false?


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;
Dreamcooled 24-Feb-12 14:56pm
As I said, I wanna enter the informations via the redirected stream (so I have to set RedirectStandardInput to true).

When I redirect nothing, everything works fine, but that's not the goal (because I wanna hide the window later).
wizardzz 24-Feb-12 15:03pm
You confused me with this statement; "But I want to provide these informations over the standart input stream!" I'm trying to help, but you don't seem to know how to redirect an input stream. Did you even look at my link? Have you set a StreamWriter to the process's StandardInput?
Dreamcooled 24-Feb-12 15:32pm
Well I'm sorry for this uncertainty. I checked out your link, and I think I know really well how to redirect a input stream :). But what should I write to the stream (not implemented in the copied source) if the process ends directly after starting? The problem is that the process doesn't wait on my inputs!
wizardzz 24-Feb-12 15:34pm
So, to clarify, you ARE writing the password to the input stream before calling p.WaitForExit()?
Dreamcooled 24-Feb-12 15:43pm
No. I start the application and log the output (see question). And I wonder why the application doesn't wait until I enter something (over the input stream), instead it just goes on.

How I want it:
I start the application.
The application asks me for the password.
I provide the password over the input stream.
The application checks the password and goes on (or prints an error).

What happens instead:
I start the application
The application asks me for the password.
(I don't do anything)
The application goes on and prints an error (even if I haven't send any char)! (But it should wait on one!)

(Btw, sorry for my bad english. It's not my mother tongue...)
wizardzz 24-Feb-12 16:09pm
This seems odd, is there code left out?
Dreamcooled 24-Feb-12 18:14pm
Just for simplification, easier argument etc. (I'm sure the bug isn't there).

Yes it's really strange. Is it possible that unrar detects the environment?
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Well, I couldn't solve the Problem. The 7zip commandline tool has similar issues.
I've modified the provided C# Wrapper for the Unrar.dll, which can be found in the download from their side. It seems as if I could customize the wrapper to my needs (as a Workaround for the Problem).
Dave Kreskowiak 27-Feb-12 11:45am
Too bad I didn't see this post earlier. I would have told you that console password entry schemes don't usually use the StdIn stream of the console but instead check for the keystrokes themselves.

In my experience, only the console commands that echo what you type as you type it in the console work with the StdIn stream. Stuff like arrow keys that move text-drawn menus never work, and password entry doesn't either.
Dreamcooled 27-Feb-12 13:58pm
Thanks a lot for your answer. Good to know for further projects :).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170326.1 | Last Updated 27 Feb 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100