Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
6.9.0 Beta2
-
None
Description
when using QProcess to launch a process, i get an error
when doing exact same thing on command line, it works.
This is my C++ code:
New Update:
On Windows
Reworked code to use only Qt idioms, mostly, also now including all my args, so you can see them. but you can tell everything you need to know by looking at the log output at the end. But first, here is the code: notes: SStringVec is same as QStringList, SuperString is same as QString
SuperString zipExecPath; SStringVec args; // zip exe to use is called "tar" zipExecPath = "tar"; // zip format args.push_back("-a"); // Create archive args.push_back("-c"); // dest file path follows: args.push_back("-f"); // dest path args.push_back(destPath.Quoted(EnquoteType_PLAIN)); // CD into source file path (truncates leading pathname in archive entries) args.push_back("-C"); // folder containing source file / folder args.push_back(GetParent().path().Quoted(EnquoteType_PLAIN)); // file / folder name to zip: args.push_back(GetName().Quoted(EnquoteType_PLAIN)); QString exePath; QString startArg; #if OPT_MACOS exePath = "/bin/sh"; startArg = "-c"; #else exePath = "cmd.exe"; startArg = "/c"; #endif // for QProcess, the app we're running is part of the args args.insert(args.begin(), zipExecPath); QStringList argList; QString argsString(SuperString(args).q_str()); // my command line args as a string argList.append(startArg); argList.append(argsString); QProcess zipProcess; zipProcess.setProgram(exePath); zipProcess.setArguments(argList); qDebug() << "------"; qDebug() << exePath << argList; qDebug() << "------"; Logf("%s %s\n", SuperString(exePath).utf8Z(), SuperString(argList.join(" ")).utf8Z()); qDebug() << "------"; if (!zipProcess.startDetached()) throw "error";
and this is what the logs spit out:
------ "cmd.exe" QList("/c", "tar -a -c -f \"\\\\?\\C:\\Users\\davec\\Music\\kJams\\kJams Library\\Songs.ksql [Backups]\\Songs 3.zip\" -C \"\\\\?\\C:\\Users\\davec\\AppData\\Local\\Temp\\kJams_Temp\\11399059660020383744\" \"Songs.ksql\"") ------ cmd.exe /c tar -a -c -f "\\?\C:\Users\davec\Music\kJams\kJams Library\Songs.ksql [Backups]\Songs 3.zip" -C "\\?\C:\Users\davec\AppData\Local\Temp\kJams_Temp\11399059660020383744" "Songs.ksql" ------
however, when .startDetached() is called, exactly nothing happens. no log error, no zip file is created.
but if i copy-paste my "Logf()" output to the command line, it works. so what is different?
Update:
note that the Logf() function is just an alias printf(). the .utf8Z() just returns the utf8-encoded c-string.
QProcess zipProcess; QStringList argsNoQuotes(args.NoQuotes()); // quoted args do not need to be quoted zipProcess.setProgram(zipPath); zipProcess.setArguments(argsNoQuotes); Logf("%s %s\n", zipPath.utf8Z(), SuperString(argsNoQuotes.join(" ")).utf8Z()); if (!zipProcess.startDetached()) throw "error";
and here's the log of THAT:
/usr/bin/zip -b /tmp -j -9 /Users/davec/Music/kJams wtf/kJams Library bellamy/Songs.ksql [Backups]/Songs 1.zip /private/var/folders/wj/h6k40dgn4sq6l98trqd3qlyh0000gn/T/TemporaryItems/kJams_Temp/9241591342633582592/Songs.ksql zip I/O error: No such file or directory zip error: Temporary file failure ( /tmp/zi8G0zZQ)
You can see the first line of the log shows the QStringList args as a string, separated by spaces (.join(" ")) so you now know the literal contents of the args, and they no longer have quotes, as suggested in a below comment.
I thought maybe the I/O error might be that the dest zip file did not exist yet, but if i create it first, empty, and left closed before the .startDetached() call, i get this:
zip warning: missing end signature--probably not a zip file (did you zip warning: remember to use binary mode when you transferred it?) zip warning: (if you are trying to read a damaged archive try -F) zip error: Zip file structure invalid (/Users/davec/Music/kJams wtf/kJams Library bellamy/Songs.ksql [Backups]/Songs 1.zip)
Then, as mentioned in a comment:
> If you want to launch a shell command line, execute /bin/sh, with exactly two parameters
when i try that on my linux-like system (macOS) it works. but it does NOT work on Windows. What would be the equivalent for windows?
Older description:
QProcess zipProcess; zipProcess.setProgram(zipPath); zipProcess.setArguments(args); Logf("%s %s\n", zipPath.utf8Z(), SuperString(args).utf8Z()); if (!zipProcess.startDetached()) throw "error"
note that output from the "Logf" function is this:
/usr/bin/zip -b /tmp -j -9 "/Users/davec/Music/kJams wtf/kJams Library bellamy/Songs.ksql [Backups]/Songs 1.zip" "/private/var/folders/wj/h6k40dgn4sq6l98trqd3qlyh0000gn/T/TemporaryItems/kJams_Temp/13026023491135078400/Songs.ksql"
note output from `startDetached()` is this:
zip warning: name not matched: "/private/var/folders/wj/h6k40dgn4sq6l98trqd3qlyh0000gn/T/TemporaryItems/kJams_Temp/13026023491135078400/Songs.ksql" zip error: Nothing to do! ("/Users/davec/Music/kJams wtf/kJams Library bellamy/Songs.ksql [Backups]/Songs 1.zip")
note that that file DEFINITELY exists:
(see screen shot)
note that if i copy-paste the output from "Logf" into Terminal, i get this:
pandora:Development davec$ /usr/bin/zip -b /tmp -j -9 "/Users/davec/Music/kJams wtf/kJams Library bellamy/Songs.ksql [Backups]/Songs 1.zip" "/private/var/folders/wj/h6k40dgn4sq6l98trqd3qlyh0000gn/T/TemporaryItems/kJams_Temp/13026023491135078400/Songs.ksql" adding: Songs.ksql (deflated 80%) pandora:Development davec$