通过c代码提取rar文件

发布于 2024-09-15 03:36:45 字数 1141 浏览 2 评论 0原文

可能的重复:
通过c打开rar文件

我必须使用c代码提取rar文件。首先我尝试寻找图书馆。我从 http://www.unrarlib.org/ 获取它。但它是2002年构建的。所以它不支持当前的rar格式。然后我检查了http://www.rarlabs.com/rar_add.htm。它有库,但是是 C++ 的。我对c++一无所知,所以我不能使用它们。我尝试通过使用系统功能来使用命令行工具unrar。当我在 CMD 中使用 unrar 时,它提取了文件,但是当我在 C 中使用它时,(命令是 system("unrar -e -p password protected_file.rar");) 它刚刚打开了档案。它没有提取该文件。现在我不知道下一步该做什么?有人能给我建议吗?

这是我用来打开rar文件的代码。系统命令中的ranjit是密码。它给出了模块+文件名中未定义的符号系统错误。 有人可以帮助我吗?两天以来我一直在努力解决这个问题。

#include<stdio.h>
#include<stdlib.h>
int main(int argc, char **argv)
     {
     char file[20];
     char file2[50] = "F:\\Program Files\\WinRAR\\unrar.exe";
     printf("enter the name of the rar file : ");
     gets(file);
     puts(file);
     system(("%s e -p ranjit %s >C:\stdout.log 2>C:\stderr.log",file2, file));
     getchar();
     return 0;
     }

Possible Duplicate:
opening a rar file by c

I have to extract a rar file using c code. First I tried out to find the libraries. I got it from http://www.unrarlib.org/. But it was built in 2002. So it do not support the current rar format. Then I checked http://www.rarlabs.com/rar_add.htm. It have libraries but in c++. I don't know anything about c++, So I can't use them. I tried to use the command line tool unrar by using system function. When I used unrar in CMD , It extracted the file but when I used it in C, (command was system("unrar -e -p password protected_file.rar");)
It just opened the archieve. It did not extract the file. Now I don't know what to do next? Can anybody suggest me something??

This is the code I am using to open the rar file.In the system command ranjit is the password. It's giving the error undefined symbol_system in module+thefile name.
Can anybody help me?? I am struggling on this since two days.

#include<stdio.h>
#include<stdlib.h>
int main(int argc, char **argv)
     {
     char file[20];
     char file2[50] = "F:\\Program Files\\WinRAR\\unrar.exe";
     printf("enter the name of the rar file : ");
     gets(file);
     puts(file);
     system(("%s e -p ranjit %s >C:\stdout.log 2>C:\stderr.log",file2, file));
     getchar();
     return 0;
     }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗藏城府 2024-09-22 03:36:46

unrar 的手册页位于此处。根据手册,命令语法是:

unrar <command> [-<switch 1> -<switch N>] archive [files...] [path...]

您提到您正在使用命令unrar -e -p password protected_file.rar来提取存档。尝试添加可选的最终参数 [path...] 并查看是否有帮助。当省略该路径时,该路径很可能被假定为当前目录。当您从 shell 运行命令时,一切都会按预期进行。当您在 C 中使用 system 命令运行时,您不知道当前目录是什么。手动指定一个目录来将存档解压到其中,看看是否会发生任何变化。

如果仍有问题,请尝试将 unrar 命令的标准输出和标准错误重定向到文本文件。该实用程序可能会在控制台上为您提供您看不到的重要信息,因为您没有直接启动它。尝试:

system("unrar -e -p password file.rar >C:\stdout.log 2>C:\stderr.log");

并在程序退出后检查日志文件。

The manual page for unrar is here. According to the manual, the command syntax is:

unrar <command> [-<switch 1> -<switch N>] archive [files...] [path...]

You mention that you are using the command unrar -e -p password protected_file.rar to extract the archive. Try adding on the optional final parameter [path...] and see if that helps. Chances are, the path is assumed to be the current directory when it is omitted. When you run the command from the shell, everything works as expected. When you run using the system command from within C, you don't know what the current directory is. Manually specify a directory to extract the archive into and see if that changes anything.

If you are still having problems, try redirecting the standard output and standard error of your unrar command to a text file. The utility may be giving you important information on the console that you are not seeing because you are not launching it directly. Try:

system("unrar -e -p password file.rar >C:\stdout.log 2>C:\stderr.log");

and check the log files after your program exits.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文