| View previous topic :: View next topic |
| Author |
Message |
ScripterFromHeaven
Joined: 03 Apr 2007 Posts: 31
|
Posted: Fri May 25, 2007 9:42 pm Post subject: Parsing console parameters |
|
|
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 |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5888
|
Posted: Sat May 26, 2007 7:22 am Post subject: |
|
|
Can you explain more?  |
|
| Back to top |
|
 |
nick
Joined: 24 Aug 2005 Posts: 345 Location: Berlin / Germany
|
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Sat May 26, 2007 9:09 am Post subject: |
|
|
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 |
|
 |
JGR
Joined: 15 Jun 2006 Posts: 52 Location: Unavailable until ~30th August
|
Posted: Sat May 26, 2007 9:28 am Post subject: |
|
|
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 |
|
 |
amouse Guest
|
Posted: Sat May 26, 2007 12:59 pm Post subject: |
|
|
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
|
Posted: Sun May 27, 2007 9:49 pm Post subject: |
|
|
| Thanks a lot all, some very useful information here. If anybody is interested in my results, I'll post them tomorrow. |
|
| Back to top |
|
 |
|