AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Parsing console parameters

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
ScripterFromHeaven



Joined: 03 Apr 2007
Posts: 31

PostPosted: Fri May 25, 2007 9:42 pm    Post subject: Parsing console parameters Reply with quote

Hello,

Has somebody of you already written a parser function for console parameters, like:

Code:

script.exe par1=0 par2="second parameter" par3=-445


If not, I'll write one.
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 5888

PostPosted: Sat May 26, 2007 7:22 am    Post subject: Reply with quote

Can you explain more? Rolling Eyes
Back to top
View user's profile Send private message
nick



Joined: 24 Aug 2005
Posts: 345
Location: Berlin / Germany

PostPosted: Sat May 26, 2007 9:02 am    Post subject: Reply with quote

http://www.autohotkey.com/docs/Scripts.htm#cmd Question
_________________
nick

denick @ http://de.autohotkey.com/forum/
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Sat May 26, 2007 9:09 am    Post subject: Reply with quote

He wants to parse each parameter, ie. 1, 2, etc., separating a parameter name from its value, a bit like GNU's getopt.
A simple StringSplit can do the trick, or a regex to take care of quoted parameters.
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
JGR



Joined: 15 Jun 2006
Posts: 52
Location: Unavailable until ~30th August

PostPosted: Sat May 26, 2007 9:28 am    Post subject: Reply with quote

To get standard windows argument delimitation you can use the API call CommandLineToArgvW (this is one of the only functions which only has a unicode version unfortunately), in shell32.dll.
You should beware windows' arcane treatment of quotes and backslashes though, as I have been bitten by that before...

Win32 Programmer's Reference
Code:
The CommandLineToArgvW function parses a wide-character Unicode command-line string. It returns a pointer to a set of wide-character Unicode argument strings and a count of arguments, similar to the standard C run-time argv and argc values. The function provides a way to obtain a Unicode set of argv and argc values from a Unicode command-line string.

LPWSTR *  CommandLineToArgvW(

    LPCWSTR lpCmdLine,   // pointer to a command-line string
    int *pNumArgs    // pointer to a variable that receives the argument count
   );   
 

Parameters

lpCmdLine

Pointer to a null-terminated Unicode command-line string. An application will usually directly pass on the value returned by a call to GetCommandLineW.

*pNumArgs

Pointer to an integer variable that the function sets to the count of arguments parsed.

 

Return Values

If the function succeeds, the return value is a non-NULL pointer to the constructed argument list, which is a set of Unicode wide-character argument strings.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Remarks

It is the caller's responsibility to free the memory used by the argument list when it is no longer needed. To free the memory, use a single call to either the GlobalFree or LocalFree function.
Back to top
View user's profile Send private message
amouse
Guest





PostPosted: Sat May 26, 2007 12:59 pm    Post subject: Reply with quote

Is this what you are looking for: processing command line parameters

Or if you want the "raw" command line with quotes, white-space and
everything else try:

Code:
commandline := DllCall( "GetCommandLine", "str" )


If I remember corrrectly, this returns the command line as typed.
Back to top
ScripterFromHeaven



Joined: 03 Apr 2007
Posts: 31

PostPosted: Sun May 27, 2007 9:49 pm    Post subject: Reply with quote

Thanks a lot all, some very useful information here. If anybody is interested in my results, I'll post them tomorrow.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group