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

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

问题描述

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

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 Files\7-Zip\7z.exe -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 是特定对象的迭代器

推荐答案

似乎是某些东西在第一个参数周围加上了引号。您可以尝试使用额外的引号来尝试解决此问题,或者可以使用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〜1\7-ZIP\7Z.EXE

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

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

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