7-Zip 7za命令行无法找到指定的文件

时间:2011-09-12 15:23:42

标签: c# visual-studio-2010 zip 7zip

我有C#程序使用7za.exe使用“l”命令检查zip存档,然后使用“e”命令解压缩。有关7-Zip命令行的信息,请访问:http://www.dotnetperls.com/7-zip-examples

我可以从服务器上的桌面运行该程序并且它运行良好,但是直接在服务器上运行它会产生以下异常:“系统找不到指定的文件”。我已经验证文件路径是正确的并且正在传递给7za.exe。我在项目中附加了7za.exe作为嵌入式资源,不知道为什么它找不到文件?有任何想法吗?谢谢!

以下是我必须验证的代码,我可以打开zip存档,除了l是e之外,解压缩的代码大致相同。

Process l = new Process();
l.StartInfo.FileName = "7za.exe";
l.StartInfo.Arguments = "l " + filePath[i];
l.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
l.EnableRaisingEvents = true;
l.StartInfo.UseShellExecute = false;
l.StartInfo.RedirectStandardOutput = true;
l.Start(); // This is were it throuws the exception because it can't find the file.
// Do stuff to verify zip archive is not corrupt
l.WaitForExit();

Ex:filePath [i] = C:\ Users \ Me \ Desktop \ ZipFile.zip

1 个答案:

答案 0 :(得分:1)

“嵌入式资源”只能与.NET资源API一起使用,它不会创建单个文件,也不能通过正常的Windows函数找到,例如CreateProcess(这是Process.Start 1}}使用)。