Results 1 to 9 of 9

Thread: quote in command promps

  1. #1
    Join Date
    Dec 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default quote in command promps

    How can I use quotes for execute parameters in Windows?
    I need use mask like "*", but without quotes Qt application replace * like all files in current directory. From second application (GUI for first) I use code like this
    Qt Code:
    1. QProcess *proc = new QProcess();
    2. QString findproc("./find2db");
    3. QStringList findparam;
    4. QString mask("\"*\"");
    5. findparam << mask << dir;
    6. proc->start(findproc, findparam);
    To copy to clipboard, switch view to plain text mode 
    But after I execute it I see that mask like \"*\" or * or \*\ but never like "*"

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: quote in command promps

    You need to escape the escape slash: "\\"*\\""
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: quote in command promps

    Qt and C++ are not expanding the "*" wildcard, that is the shell involved.

    You can also use single quotes or a backlash:
    Qt Code:
    1. QString mask("'*'"); // double-quote single-quote asterisk single-quote double-quote
    2. QString mask("\\*");
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Dec 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: quote in command promps

    "\\"*\\"" = three objects: string "\", * not in string and second string "\"

    mask "'*'" return to string '*'
    mask "\\*" return to string \*
    but it's wrong. For sample
    Qt Code:
    1. dir \*
    To copy to clipboard, switch view to plain text mode 
    can't work!


    Added after 10 minutes:


    I test little sample on gcc, Borland C++ Builder and MS Visual C
    Qt Code:
    1. #include <stdio.h>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. for (int i=0; i<argc; i++)
    6. {
    7. printf("%s\n", argv[i]);
    8. }
    9. return 0;
    10. }
    To copy to clipboard, switch view to plain text mode 
    One parameter for test - *
    Builder and Visual C samples work fine (i see * after run). gcc return all files in directory. That's not fine.


    Added after 52 minutes:


    Quote Originally Posted by ChrisW67 View Post
    Qt and C++ are not expanding the "*" wildcard, that is the shell involved.

    You can also use single quotes or a backlash:
    Qt Code:
    1. QString mask("'*'"); // double-quote single-quote asterisk single-quote double-quote
    2. QString mask("\\*");
    To copy to clipboard, switch view to plain text mode 
    mask '*' not understood by nameFiltersFromString
    Qt Code:
    1. QFileInfoList list = (dir.entryInfoList(QDir::nameFiltersFromString(filemask)));
    To copy to clipboard, switch view to plain text mode 
    mask "\\*" parsed to \* and return all files in root of current drive in Windows.
    Last edited by QuAzI; 15th December 2010 at 07:44.

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: quote in command promps

    What is the string you want as a result?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #6
    Join Date
    Dec 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: quote in command promps

    1) I want to have "*" (double quoted asterisk) after QProcess::start()
    2) I want to view real argv[] arguments in secondary program
    In secondary program I use argv[] for recursive listing files in some directories. Function
    QDir::nameFiltersFromString(filemask)) return list of parameters delimeted by space.
    I can use it like this
    Qt Code:
    1. ./prog2 "*.c *.obj *.h" second_parameter
    2. ./prog2 "*" second_parameter
    To copy to clipboard, switch view to plain text mode 
    But now QProcess delete double quotes and except one parameter I have three parameters. But second parameter must be not file mask.
    Also I want use it with one mask like
    Qt Code:
    1. ./prog2 * second_parameter
    To copy to clipboard, switch view to plain text mode 
    but I cant because gcc interpreter mask like all files in current directory.

    first parameter in secondary program used by this code
    Qt Code:
    1. QDir dir(directory);
    2. dir.setFilter( QDir::Files | QDir::Readable | QDir::AllDirs | QDir::NoDotAndDotDot );
    3. QFileInfoList list = (dir.entryInfoList(QDir::nameFiltersFromString(filemask)));
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: quote in command promps

    And this: "\"*\"" doen't work?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  8. #8
    Join Date
    Dec 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: quote in command promps

    In FreeBSD all fine.
    In Windows I have \"*\" and QDir::nameFiltersFromString(filemask) can't understan it. Also can't understand '*' \* \Q and other variations.

  9. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: quote in command promps

    OK, so if you send just an asterisk through QProcess your second program never sees the asterisk, just an expanded list of files. You want the second program to receive a literal asterisk in its argv array.

    You can try passing:
    Qt Code:
    1. QString mask("^*");
    To copy to clipboard, switch view to plain text mode 
    The Windows shell uses the caret as an escape character in some circumstances. This is, of course, utterly non-portable.

    The auto-expansion of file patterns by the command shell can be turned off:
    http://stackoverflow.com/questions/2...ngw-on-windows
    http://oldwiki.mingw.org/index.php/TestForGlobbing
    This would have to happen in your second program. I did not have much luck with this.
    Last edited by ChrisW67; 15th December 2010 at 21:59.

Similar Threads

  1. Replies: 7
    Last Post: 20th October 2012, 13:44
  2. What does this command mean?
    By mr.dct in forum Newbie
    Replies: 14
    Last Post: 23rd March 2010, 09:52
  3. Replies: 4
    Last Post: 14th July 2009, 03:27
  4. SQL command and QString?
    By SunnySan in forum Newbie
    Replies: 9
    Last Post: 11th September 2008, 22:56
  5. Insertion double quote into string/qstring
    By MarkoSan in forum General Programming
    Replies: 12
    Last Post: 14th December 2007, 12:23

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.