Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. QProcess not launching exe in Microsoft OneDrive directory

QProcess not launching exe in Microsoft OneDrive directory

Scheduled Pinned Locked Moved Solved C++ Gurus
8 Posts 5 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    ktwalker
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      K 1 Reply Last reply
      1
      • SGaistS SGaist

        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 ?

        K Offline
        K Offline
        ktwalker
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • K Offline
          K Offline
          ktwalker
          wrote on last edited by ktwalker
          #4

          @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

          JKSHJ JonBJ 2 Replies Last reply
          0
          • K ktwalker

            @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

            JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by JKSH
            #5

            @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 (").

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            5
            • K ktwalker

              @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

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @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").

              1 Reply Last reply
              5
              • fcarneyF Offline
                fcarneyF Offline
                fcarney
                wrote on last edited by
                #7

                @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.

                C++ is a perfectly valid school of magic.

                1 Reply Last reply
                3
                • K Offline
                  K Offline
                  ktwalker
                  wrote on last edited by ktwalker
                  #8

                  Folks,

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

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

                  Kris

                  1 Reply Last reply
                  2

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved