[Closed] Using DOSCommand() with 7Zip
Hello all. In my maxscript, I need to create a zip archive. I found that maz() was not flexible enough, so I downloaded 7Zip.
In my code, I use DOSCommand() to use 7zip. Before I use DOSCommand(), I print its command that I put together.
(I have 7zip installed at C:\Program Files\7-Zip\ and the command line version of 7Zip is 7z.exe)
"C:\Program Files\7-Zip\7z.exe" a -tzip "C:\TEST_LEVEL.MAP" "C:\3dsmax7\TEST_LEVEL.XML" "C:\3dsmax7\Ground01.b3d" "C:\3dsmax7\Ground01LightingMap.png" "C:\3dsmax7\Ground01DiffuseMap.png" "C:\3dsmax7\guard tower01.b3d" "C:\3dsmax7\guard tower01LightingMap.png" "C:\3dsmax7\metal120.jpg" "C:\3dsmax7\guard tower03.b3d" "C:\3dsmax7\guard tower03LightingMap.png" "C:\3dsmax7\Circle05.b3d" "C:\3dsmax7\Circle05LightingMap.png" "C:\3dsmax7\metal097.jpg" "C:\3dsmax7\Box96.b3d" "C:\3dsmax7\metal061.jpg" "C:\3dsmax7\Box97.b3d" "C:\3dsmax7\Box98.b3d" "C:\3dsmax7\Box99.b3d" "C:\3dsmax7\Box100.b3d" "C:\3dsmax7\dynamic_crate3.b3d" "C:\3dsmax7\dynamic_crate.b3d" "C:\3dsmax7\dynamic_crate2.b3d"
Now this looks fine- but when I run the script the DOS window shows for about half a second then dissapears. I navigate to where I said to create the archive, and there is no zip file created. I made sure that every file was there I requested to put in the zip file, and then repeated the same command in command prompt (not using DOSCommand()). When I did, 7zip compressed everything and the zip file was created. So how could this same command work outside of 3ds max in command prompt and not work with DOSCommand()? I tried then appending ” >> C:\output.txt” to the command that I sent to DOSCommand(), but a file C:\output.txt was created with no text in it, zero bytes, and no zip archive was created. I repeated the exact same command outside of maxscript in the command prompt, and the zip file was created and the output.txt contained text saying the zip file was successfully created.
I thought that DOSCommand() was the equivalent of giving a command to command prompt but I thought wrong?
Edit: I apologize, I did some more searches on the forum with different keywords and brought up some useful threads. After reading this thread I decided to create a bat file there and use ShellLaunch(). Everything works now by doing this. A mod can delete this thread.
You have a problem and provide a resolution.
That’s not a deletion offense that’s a useful post.
The fact that you didn’t find the answer you were looking for with keywords you would think of is proof that the archive wasn’t sufficiently thorough.
As to why it failed: I would wager if it wasn’t the \ literal problem it is because DosCommand chokes on really long commands… which your command certainly falls in the category of.
if you’d like to be even more flexible you could also try the DotNetZip Library. i found that’s a really good way to create zip files.
Hehe. Either the archive wasn’t sufficiently thorough or I choose a bad choice of key words
I’d like to keep compatibility with older versions of 3ds max- My user base won’t be a professional one. Isn’t DotNet only available for versions of 3ds Max 9 or higher?
And so far 7Zip has been working very nicely.
However, there has been one problem I’ve encountered while using ShellLaunch(). The problem is how my program knows once ShellLaunch() is done executing. Because, since it’s an external execution by windows, my program will move through the next lines of code while ShellLaunch() is still executing. This is a problem because my program automatically exports geometry into mesh files and zips them- but after I zip them there’s no need for the mesh files to remain on my hard disk. If I try to use deleteFile(), then the problem occurs where I am deleting a file while 7Zip is in the process of zipping it. I’ve thought of ways to leave the files on the harddrive in a polite fashion, but does anyone have any ideas how to put the script in a stall until I know that 7Zip is done zipping?