System() function for the path including blanks.

  • Dear Qt developer and experts.

    I found that the the system() function does not work when the path including blanks.
    Would you check this? I spend a day for this. ^^;

    The following code using the path including blanks does not work.

    sprintf( buff, " "C:\\Program Files (x86)\\tool\\tool.exe" argument");
    system( buff );;

    If the path does not have blank, the system() function works well (as follows).

    sprintf( buff, "D:\directory\GUI\tool\QC\tool.exe");
    system( buff );;

    Thank you very much.
    I really appreciate to the Qt developers. It the the best tool.

    Sincerely Yours,

    Ick-Sung Choi.

  • Moderators


    Do you get into your "buff" variable the expected string that you have passed ? Try printing it.

  • I have this problem too :(

  • Use this:
    @sprintf(buff, "C:\"Program Files"\CCleaner\CCleaner64.exe"); @

    Note the "Program Files" put in quotes using Escape character(")

  • Dear experts.
    Thank you very much for comment and advices.
    Yes. I tried to print the buff string. The string is executed well when I put it in DOS cmd.exe.

    I wrote the string to "run.bat" file. and I execute the "run.bat" using system("run.bat").

    Thank you blueshift for your advice.
    I will try it.

    Thank you very much.

    Sincerely Yours,

    Ick-Sung Choi.

  • For future reference none of this has anything to do with Qt.

    system() is a C/C++ standard library function.
    The need to quote paths containing spaces is s function of the command shell that system() launches on your behalf.
    The way you escape quotes and backslashes in a C literal string is governed by the C/C++ language.

    If you want a Qt equivalent please look at the QProcess class.

  • Dear ChrisW67.

    Thank you very much for your precious advice.
    I am not good at C++ and Qt .
    I started to study Qt just a month ago. ^^;

    Thank you very much.
    Sincerely Yours,

    Ick-Sung Choi.

  • Yes ChrisW67 is right. It is advisable to use QProcess for what you intend. Calling system() is highly undesirable.
    Regards and thanks,

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.