Jump to content

Difference between $CmdLine and _WinAPI_CommandLineToArgv


mwhidden
 Share

Recommended Posts

I'm not sure if this is the expected behavior, but the way $CmdLine handles escaped quotes is different than _WinAPI_CommandLineToArgv (which is recommended as an alternative for long argument lists) handles them.

Eg., When invoked like this:

AutoIt3.exe Test.au3 "A B\" C" A B C

$CmdLine gives 2 arguments after the length: [ ..., 'A B', 'C" A B C"]

_WinAPI_CommandLineToArgv gives 4 arguments after the script: [..., 'A B" C', 'A', 'B', 'C']

Is this as it should be?

Thanks,

Mike

#include <WinAPIShPath.au3>
#include <Array.au3>
_ArrayDisplay(_WinAPI_CommandLineToArgv($CmdLineRaw))
_ArrayDisplay($CmdLine)
Link to comment
Share on other sites

That's a pretty unusual set of arguments.

I imagine, that AutoIt is being kind to you with $CmdLine, and not requiring the fourth quote, which is missing.

I expect otherwise, that $CmdLine and _WinAPI_CommandLineToArgv act the same, though I have never used the latter.

If one doesn't want spaces to be used as dividers between arguments, then quotes are required.

_WinAPI_CommandLineToArgv may be ignoring the second quote as a divider, because there is no fourth?

The fact, that the first 'C' seems to be in your second argument result for $CmdLine, would seem to indicate that AutoIt is a little confused and just abides by some predetermined policy.

If you wanted 'C"' to be a separate argument, you would have to enclose it as I just did, in single quotes.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

That's a pretty unusual set of arguments.

I imagine, that AutoIt is being kind to you with $CmdLine, and not requiring the fourth quote, which is missing.

 

Sorry, I think my explanation was not clear.

"A B" C" is a manufactured argument for illustration of parsing an escaped double quote embedded in an argument. A real-life example might be something more like

SendEmail.au3 "My boss said "Finish this script" today. Can you believe it? -MWhidden"

The single argument to the script would be a string with double quotes within it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...