在c ++中使用7

编程入门 行业动态 更新时间:2024-10-26 00:31:32
在c ++中使用7-zip via system()(Using 7-zip via system() in c++)

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

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

"C:\Program Files\7-Zip\7z.exe" a -tzip "bleh.zip" "addedFile.txt"

其中吐出了错误

'C:\Program' is not recognized as an internal or external command, operable program or batch file.

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

我想尝试从它的安装目录直接运行它,以便只要用户安装了7-Zip,它就能够运行。 这是一个内部实用程序应用程序。

编辑:按要求这些是实际的代码行:

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

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

"C:\Program Files\7-Zip\7z.exe" a -tzip "bleh.zip" "addedFile.txt"

which spat the error

'C:\Program' is not recognized as an internal or external command, operable program or batch file.

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

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.

EDIT: 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 is an iterator to a particular file that is getting added.

最满意答案

它看起来像是在第一个参数周围删除引号。 您可以使用额外的引号来尝试修复此问题,也可以使用Win32 API获取与MS-DOS兼容的7z.exe短路径名称GetShortPathName

短路径中不会有空格,它会像“C:\ PROGRA〜1 \ 7-ZIP \ 7Z.EXE”

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

The short path will not have spaces in it, it will be something like "C:\PROGRA~1\7-ZIP\7Z.EXE"

更多推荐

本文发布于:2023-07-29 20:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1319531.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!