QProcess not launching exe in Microsoft OneDrive directory



  • Folks,

    I have the following code to launch Program.exe from the directory that the main calling program is launched from.

    void WorkFlow::launchProgram()
    {
    	QString dirName = QCoreApplication::applicationDirPath();
    	AddSeparator(&dirName);    // Adds appropriate path separator for Windows and Linux
    	QString exeName = dirName + "Program.exe";
    	QProcess Program;
    	Program.startDetached(exeName);
    }
    
    

    It will successfully launch Program.exe from C:\temp directory when I move the executables there. However, when I have the executables on my Microsoft OneDrive, it will not launch. I have the same failed result if I use the "system()" command. The system command reports back an error in parsing the path. I am not smart enough yet to know how to get errors back from the below QProcess attempt. The OneDrive path is linked to my Documents directory:

    My one drive is linked to:

    "C:\Users\MyUserName\Documents\OneDrive - A.lnk"

    this dereferences in File Explorer to

    "C:\Users\MyUserName\OneDrive - A"

    Does anyone have advice for how to make this program work regardless if the executables are on the OneDrive or on a physical drive?

    Thank you,
    Kris


  • Lifetime Qt Champion

    Hi,

    If the system call itself doesn't work, QProcess will likely not make miracles. What does Program.exe do ? Does it work if you start it from the command line inside that folder ?



  • @SGaist I cannot navigate into the OneDrive with the cmd shell, presumably because Windows 10 cmd environment does not dereference the link correctly.



  • @SGaist I can use PowerShell however to navigate into the directory. I am able to execute the launch Program.exe from the PowerShell command line. I notice that the permissions are listed as

    -a---l Program.exe

    when I list the directory contents.

    Update:

    I did an experiment by copying the executable and its launching executable to a directory on my physical drive that I called "TwoDrive - B". It failed to launch from that directory as well. I removed the "-" and it still failed. I removed the white space and it worked. So the issue is that QProcess and system are not liking the space in the directory name. This is 2019. It's hard to believe that this is really the issue. This would seem to be a practical issue that some people face quite often. Is there a workaround or upcoming QProcess method that will handle these spaces accordingly?

    Kris


  • Moderators

    @ktwalker said in QProcess not launching exe in Microsoft OneDrive directory:

    I removed the white space and it worked. So the issue is that QProcess and system are not liking the space in the directory name. This is 2019. It's hard to believe that this is really the issue. This would seem to be a practical issue that some people face quite often. Is there a workaround or upcoming QProcess method that will handle these spaces accordingly?

    In the Windows command line, a space is used to separate multiple arguments. So, C:\Users\MyUserName\Documents\OneDrive - A.lnk is interpreted as:

    • Executable's path: C:\Users\MyUserName\Documents\OneDrive
    • Arg 1: -
    • Arg 2: A.lnk

    If the path contains spaces, the practical person shall wrap the path in double-quotes (").



  • @ktwalker

    So the issue is that QProcess and system are not liking the space in the directory name. This is 2019. It's hard to believe that this is really the issue. This would seem to be a practical issue that some people face quite often

    The issue/behaviour/resolution has been the same for about 30 years now.

    Is there a workaround or upcoming QProcess method that will handle these spaces accordingly?

    Yes, you need to read up on how to correctly pass paths with spaces to Windows, Qt or not. Even the QProcess docs cover this ("quoting").



  • @JKSH said in QProcess not launching exe in Microsoft OneDrive directory:

    This is 2019. It's hard to believe that this is really the issue.

    The problem is the same problem computer users have always faced with computers. Computers cannot cope with ambiguous data. Programmers and users have learned to be more concise with the data they present. While computer interfaces have learned to interpret user input better, it is still at some point going to require concise input to function properly. AI is an attempt to interpret data and input in a more "human" way, but it depends highly on the training data being bounded and concise.

    Just like @JKSH and @JonB pointed out. To present a path in a more concise manner you bound it with quotes.
    Concise (computer sees 3 distinct tokens):

    "C:\Users\MyUserName\Documents\OneDrive - A.lnk" -c -t
    

    Ambiguous (computer sees 5 distinct tokens):

    C:\Users\MyUserName\Documents\OneDrive - A.lnk -c -t
    

    I added -c and -t as examples of other parameters presented on the command line. A token is a unit of text that would be grouped together by a parser of the command line.

    So, as of 2019, computers really cannot cope with ambiguous data in a meaningful precise way. I am guessing, that when computers can do this, Skynet will be alive.



  • Folks,

    Thanks for the direction. The escape character for QStrings is \. So the solution is

    QString exeName = "\"" + dirName + "Program.exe\"";
    
    

    Kris


Log in to reply