在 C++ 中通过 system() 使用 7-zip [英] Using 7-zip via system() in c++

查看:33
本文介绍了在 C++ 中通过 system() 使用 7-zip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Windows XP 机器上通过 C++ 中的 system() 函数使用 7-Zip 压缩文件.我试过了:

I'm trying to use 7-Zip to zip up a file via the system() function in C++ on a windows XP machine. I tried:

(格式化为 system() 会收到的内容)

(formatted to be what system() would have received)

"C:Program Files7-Zip7z.exe" a -tzip "bleh.zip" " addedFile.txt"

哪个吐出了错误

'C:Program' 不被识别为内部或外部命令,可运行的程序或批处理文件.

我尝试了几种类似的替代方法,但还没有找到解决方案.

I've tried several similar alternatives but have not yet found a solution.

我想尝试直接从它的安装目录运行它,这样只要用户安装了 7-Zip,它就可以运行.这是用于内部实用程序应用程序.

I want to try to run it straight from its install directory so that as long as a user has 7-Zip installed it will be able to function. This is for an in house utility application.

根据要求,这些是实际的代码行:

as requested these are the actual lines of code:

std::string systemString = ""C:\Program Files\7-Zip\7z.exe" a -tzip "" + outDir + projectName + ".zip" + "" "";
//...
std::string finalSystemString = systemString + *i + """;
system( finalSystemString.c_str() );

*i 是正在添加的特定文件的迭代器.

*i is an iterator to a particular file that is getting added.

推荐答案

它看起来像是在剥离第一个参数周围的引号.您可以使用额外的引号来尝试解决此问题,或者您可以使用 Win32 API GetShortPathName

it looks like something is stripping the quotes around the first argument. You could play around with extra quotes to try and fix this, or you can get the MS-DOS compatible short path name for 7z.exe with the Win32 API GetShortPathName

短路径中不会有空格,它将类似于C:PROGRA~17-ZIP7Z.EXE"

The short path will not have spaces in it, it will be something like "C:PROGRA~17-ZIP7Z.EXE"

这篇关于在 C++ 中通过 system() 使用 7-zip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆