Platform Qt 5.15.2 Windows.
I have a function that uses this code:
QString commstr = "c:/temp/cpath.bat";
QProcess::startDetached("cmd.exe", QStringList() << "/c" << "start" << commstr);
bat file:
echo off
set PATH=%PATH%; more paths added here ...
It opens a console and runs the .bat file contained in the QString commstr
. The bat file makes a temporary change to the path then finishes, leaving the console open for further user interaction. Works great, just as intended.
Here's the weird problem: If the userid has embedded spaces i.e. "joe user" the .bat file is not run. The console opens, but commstr
is never executed. I can't for the life of me figure out why the userid matters here.
I can't imagine what part the userid plays in this. The user's home directory (e.g. "C:\Users\joe user") isn't referenced in the code, nor is the program installed there. The program works w/o issues other embedded spaces directories anyway (e.g "C:\Program Files").
QProcess::startDetached("cmd.exe", QStringList() << "/c" << "start" << "" << "/path/to/file.bat");
Adding a empty title string as the first argument following start fixed my issue.
Syntax
START "title" [/D path] [options] "command" [parameters]
Key:
title Text for the CMD window title bar (required.)
path Starting directory.
command The command, batch file or executable program to run.
parameters The parameters passed to the command.```