I want to extract .rar files using cmd shell so I wrote this code:
string commandLine = @"c:\progra~1\winrar\winrar e c:\download\TestedU.rar c:\download";
ProcessStartInfo PSI = new ProcessStartInfo("cmd.exe");
PSI.RedirectStandardInput = true;
PSI.RedirectStandardOutput = true;
PSI.RedirectStandardError = true;
PSI.UseShellExecute = false;
Process p = Process.Start(PSI);
StreamWriter SW = p.StandardInput;
StreamReader SR = p.StandardOutput;
SW.WriteLine(commandLine);
SW.Close();
The first time it worked fine, the second time it displayed nothing.
As Kjartan suggested, using 7-Zip SDK may be a better option than spawning an external executable depending on your use:
7-Zip SDK is a C/C++ library but http://sevenzipsharp.codeplex.com/ has a .Net library of it around the 7-Zip SDK which makes it easier to use in .NET.
You might skip the middle step and call the winrar.exe with the parameters straight instead of first instanciating cmd.exe
Also you might take a look at the 7-zip SDK
9 Answers, only sam mousavi is answering your question directly, but noone's telling you what's wrong. Citing from the WinRAR manual:
And that's exactly what's missing up there at
c:\download
. Right now it tries to extract the file c:\download inside the archive to the current directory. How it could work the first time is a mystery.You can use this lib directly: http://sevenziplib.codeplex.com/
We can also use this,