PDA

View Full Version : quote in command promps



QuAzI
14th December 2010, 16:07
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


QProcess *proc = new QProcess();
QString findproc("./find2db");
QStringList findparam;
QString mask("\"*\"");
findparam << mask << dir;
proc->start(findproc, findparam);

But after I execute it I see that mask like \"*\" or * or \*\ but never like "*"

high_flyer
14th December 2010, 16:15
You need to escape the escape slash: "\\"*\\""

ChrisW67
14th December 2010, 21:05
Qt and C++ are not expanding the "*" wildcard, that is the shell involved.

You can also use single quotes or a backlash:


QString mask("'*'"); // double-quote single-quote asterisk single-quote double-quote
QString mask("\\*");

QuAzI
15th December 2010, 07:44
"\\"*\\"" = three objects: string "\", * not in string and second string "\"

mask "'*'" return to string '*'
mask "\\*" return to string \*
but it's wrong. For sample


dir \*

can't work!

Added after 10 minutes:

I test little sample on gcc, Borland C++ Builder and MS Visual C


#include <stdio.h>

int main(int argc, char *argv[])
{
for (int i=0; i<argc; i++)
{
printf("%s\n", argv[i]);
}
return 0;
}

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:


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

You can also use single quotes or a backlash:


QString mask("'*'"); // double-quote single-quote asterisk single-quote double-quote
QString mask("\\*");


mask '*' not understood by nameFiltersFromString


QFileInfoList list = (dir.entryInfoList(QDir::nameFiltersFromString(fil emask)));

mask "\\*" parsed to \* and return all files in root of current drive in Windows.

high_flyer
15th December 2010, 08:43
What is the string you want as a result?

QuAzI
15th December 2010, 09:04
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


./prog2 "*.c *.obj *.h" second_parameter
./prog2 "*" second_parameter

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


./prog2 * second_parameter

but I cant because gcc interpreter mask like all files in current directory.

first parameter in secondary program used by this code


QDir dir(directory);
dir.setFilter( QDir::Files | QDir::Readable | QDir::AllDirs | QDir::NoDotAndDotDot );
QFileInfoList list = (dir.entryInfoList(QDir::nameFiltersFromString(fil emask)));

high_flyer
15th December 2010, 09:21
And this: "\"*\"" doen't work?

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

ChrisW67
15th December 2010, 21:28
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:


QString mask("^*");

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/2950978/globbing-with-mingw-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.