argv schluckt div. parameteruebergaben nicht richtig



  • VC6
    Borland 6

    int main (int argc, char **argv) {
    
    	if (argc != 4) {
    		cout <<"argc"<<argc<<endl;
    		cout <<argv[0]<<endl;
    		cout <<argv[1]<<endl;
    		cout <<argv[2]<<endl;
    //		cout <<argv[3]<<endl;
    //		help();
    	} else {
    		cout <<"argc"<<argc<<endl;
    		cout <<argv[0]<<endl;
    		cout <<argv[1]<<endl;
    		cout <<argv[2]<<endl;
    		cout <<argv[3]<<endl;
    	}
    	return 0;
    }
    

    ----------------
    shiplist /x c:\test\ d:\proof\
    argc4
    shiplist
    /x
    c:\test\
    d:\proof\

    Soweit, alles in ordnung!
    ---------------
    shiplist /x c:\test\ "d:\pro of\"
    argc4
    shiplist
    /x
    c:\test\
    d:\pro of"

    Fehler d:\pro of"
    --------------
    shiplist /x "c:\te st" "d:\pro of\"
    argc4
    shiplist
    /x
    c:\te st
    d:\pro of"

    Feler d:\pro of"
    --------------
    shiplist /x "c:\te st\" "d:\pro of\"
    argc4
    shiplist
    /x
    c:\te st" d:\pro
    of"

    Schwere fehler
    --------------
    shiplist /x "c:\te st" "d:\pro of"
    argc4
    shiplist
    /x
    c:\te st
    d:\pro of

    Alles in ordnung
    -------------

    Immer wenn am schluss ein \ steht scheint dies weder dem VC6 noch Boldand6 zu gefallen.
    Es ist zwar ungewoehnlich das jemand bei einer pfadangabe ein abschliessendes \ hinzufuegt,
    aber was ist wenn es jemand dennoch tut ....

    Ich bin durch blossen zufall darauf gestossen
    und frage mich wie wer wo was wann falsch laeuft ....

    copy jedenfalls schluckt diese verkorcksten pfadangaben alle
    ohne zu murren.

    OS: w2k, aber es soll auf allen 9x, w2k und XP`s laufen.

    Danke fuehr ihre aufmerksahmkeit!

    PS: Mit google auch hier gesucht aber kein treffer hierzu.



  • Hallo,

    das von dir festgestellte Verhalten ist völlig korrekt, ein Anführungszeichen (") kann durch Voranstellen von '\' als Parameter-Begrenzer entwertet werden, und wird hier

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang98/html/_clang_parsing_c_command.2d.line_arguments.asp

    auch von Microsoft dokumentiert:

    MSDN schrieb:

    A double quotation mark preceded by a backslash, \", is interpreted as a literal double quotation mark (").

    MfG


Anmelden zum Antworten