我试图使用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"
更多推荐
发布评论