Parsing the Command Line
-
The
wininet
library in Windows contains APIs for "cracking" and parsing network URIs into their component parts. Are you aware of any facility in Windows that performs this function for command lines? (Something that I can call from an application, not the parsing that is done when my application is launched.)The difficult we do right away... ...the impossible takes slightly longer.
-
The
wininet
library in Windows contains APIs for "cracking" and parsing network URIs into their component parts. Are you aware of any facility in Windows that performs this function for command lines? (Something that I can call from an application, not the parsing that is done when my application is launched.)The difficult we do right away... ...the impossible takes slightly longer.
Are you talking about the contents of
argc
andargv
?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
Are you talking about the contents of
argc
andargv
?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
Yes, and the executable name. I imagine each argument separated into an array, and the executable name separated.
The difficult we do right away... ...the impossible takes slightly longer.
-
Yes, and the executable name. I imagine each argument separated into an array, and the executable name separated.
The difficult we do right away... ...the impossible takes slightly longer.
Richard Andrew x64 wrote:
I imagine each argument separated into an array, and the executable name separated.
All of that is contained in the
argv
vector. For the executable name, look at the 0th item. ForWinMain()
, you may have to refer to__argc
and__argv
instead."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
Richard Andrew x64 wrote:
I imagine each argument separated into an array, and the executable name separated.
All of that is contained in the
argv
vector. For the executable name, look at the 0th item. ForWinMain()
, you may have to refer to__argc
and__argv
instead."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
Thank you David. I didn't make it clear enough at first. I meant that I want my application to be able to parse the command line of a separate process. You know how some registry keys have command lines in them? I was wondering if there is something built into Windows that can make it easy to parse them.
The difficult we do right away... ...the impossible takes slightly longer.
-
Thank you David. I didn't make it clear enough at first. I meant that I want my application to be able to parse the command line of a separate process. You know how some registry keys have command lines in them? I was wondering if there is something built into Windows that can make it easy to parse them.
The difficult we do right away... ...the impossible takes slightly longer.
Ahh, that's a horse of a different color. If you tried separating the tokens using a space as the delimiter, an issue that I see is that the path\executable name can itself contain a space. This is usually resolved by surrounding that token with quotes. So as you are parsing the whole string, you'd need to keep track of whether you were in a quote or not. If so, then spaces do not count.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
The
wininet
library in Windows contains APIs for "cracking" and parsing network URIs into their component parts. Are you aware of any facility in Windows that performs this function for command lines? (Something that I can call from an application, not the parsing that is done when my application is launched.)The difficult we do right away... ...the impossible takes slightly longer.
If you have the command line as a string you can use the CommandLineToArgvW function[^] to split it up.
-
If you have the command line as a string you can use the CommandLineToArgvW function[^] to split it up.
Bingo! Thank you!
The difficult we do right away... ...the impossible takes slightly longer.
-
If you have the command line as a string you can use the CommandLineToArgvW function[^] to split it up.
Awesome. I had no idea such a routine existed. :thumbsup:
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles