View Full Version : OS Module
Petr Schreiber
15-02-2006, 23:27
Hi,
I'm just experimenting with OS module, but I found problem.
Using OS_GetCommand() I should be able to parse out parameters, but I really don't know, what is the right separator ( to access parameters 2 and more). Of course I could separate my parameters by "," then load them all at once with OS_GetCommand(2) and then using PARSE$ parse them, but I think there must be way doing something similar using OS_GetCommand(number)
Also, there is in the table that parameter is string, maybe it should be number. It has in "See also" link to itself too :) .
Thanks,
Petr
ErosOlmi
15-02-2006, 23:36
There is a sample script under SampleScripts\OS
In any case something like that can help?
USES "Console"
USES "OS"
'Console_Cls
DIM NumberOfCommands AS LONG
DIM Count AS LONG
'---Returns the number of commands specified
NumberOfCommands = OS_GETCOMMANDS
'---Some header
CONSOLE_WRITE("The following are the passed parameters (param 1 is always script name):" & $CRLF)
CONSOLE_WRITE(REPEAT$(79, "-") & $CRLF)
'---Show all parameters
FOR Count = 1 TO NumberOfCommands
CONSOLE_WRITE( FORMAT$(Count, "00") & " " & OS_GETCOMMAND(Count) & $CRLF)
NEXT
'---If only 1 param then exit
IF NumberOfCommands <= 1 THEN
CONSOLE_WRITE( "Only 1 parameter, program stopped. Press a key to Continue" & $CRLF)
CONSOLE_WAITKEY
STOP
END IF
'---If more than 1 param, execute something ...
FOR Count = 1 TO NumberOfCommands
SELECT CASE UCASE$(OS_GETCOMMAND(Count))
CASE "COMPUTERNAME"
CONSOLE_WRITE(OS_GETCOMMAND(Count) & ": " & OS_GETCOMPUTERNAME & $CRLF)
CASE "USERNAME"
CONSOLE_WRITE(OS_GETCOMMAND(Count) & ": " & OS_GETUSERNAME & $CRLF)
END SELECT
NEXT
CONSOLE_WRITE( "Press a key to Continue" & $CRLF)
CONSOLE_WAITKEY
ErosOlmi
15-02-2006, 23:39
Valid separators are: space or = or -
I can add more but usually space or - are ok.
Let me know.
Eros
Petr Schreiber
15-02-2006, 23:59
Eros,
you are right. All the problem was caused by my fault. I made syntax error, which was too unexpected for thinBASIC parser so it was compiled with no result.
I used :
dim modelName as string os_getcommand(3)
instead of :
dim modelName as string = os_getcommand(3)
Now all works almost as expected, except from :) :
If I separate two parameters ("12345 My3D") with space ($SPC), they are parsed as "12345" and "My3D".
But with "=" or "-" they are parsed as "12345" and "-My3D" or "=My3D". Is it correct ?
Thanks,
Petr
ErosOlmi
16-02-2006, 00:04
I will check ... tomorrow :cry:
Ciao
Eros