More convenient than having to construct a proper escaped commandline.
Details
- Reviewers
dfaure - Group Reviewers
Frameworks - Commits
- R241:5f2be012c27d: [CommandLauncherJob] Add constructor taking an executable and argument list
- Ported the runners in D28512 to use it, had something with a space properly escaped
Diff Detail
- Repository
- R241 KIO
- Lint
Automatic diff as part of commit; lint not applicable. - Unit
Automatic diff as part of commit; unit tests not applicable.
KProcessRunner::KProcessRunner(QString cmd) calls KProcess::setShellCommand(cmd) which ... has two modes. Either KShell::splitArgs()[0] finds an executable that exists (checking that there is no "&&" or "||" or ";" in the command) in which case it uses the splitted args, and no /bin/sh is involved, *or* it passes the whole command as is to "sh -c", as a single argument. That first optimization aside, it is logical for setShellCommand to take a single string. So It's logical to me that KProcessRunner takes a single string, and that you join the stringlist in CommandLauncherJob.
Good question. I haven't seen that done in most callers, but indeed, what if it's in a path with a space, like often happens on Windows?
It sounds like the answer is yes, it should be quoted.
The real answer is to write a CommandLauncherJob unittest for such a case, of course :-)
Not sure how I would test running a command with a space in it.. putting a shell script in running it through QFINDTESTDATA? Not sure how to make that sort of stuff work on Windows
You could create a subdir of a QTemporaryDir with a fixed name like "abc def", copy cp or copy.exe in there, and then run that with an absolute path?