Page 1 of 1 1
Topic Options
#120362 - 2004-05-28 01:54 PM Using dos "For" command and tokens
Simon Offline
Lurker

Registered: 2004-05-28
Posts: 2
I was wondering if someone has used this successfully, maybe my syntax is wrong but it looks like using the dos for command and trying to pass the tokens (%%b) into variables doesn't work.
The scripts basically reads a line of a .csv file into $x (this works), should then grab some value for the line and pass then into variables and run another kix script. This is an idea for drive mapping scripts


Dim $rc,$Usergroup,$RemotePath,$DriveLetter,$Logfile,$x
$rc=SetOption('explicit','on')
$rc=SetOption('novarsinstrings','on')


$LogFile = "%SYSTEMROOT%\Logs\Logon.log"

If Open(3, "deptmap.txt") = 0
$x = ReadLine(3)
While @ERROR = 0
Shell 'cmd /c For /f "eol=,tokens=1,2,3,4,5,6,7 delims=," %%b In ("$x") do call kix32 configdrive2.kix $Usergroup=%%b RemoteDrive=%%e'
$x = ReadLine(3)
Loop
EndIf

thanks

Top
#120363 - 2004-05-28 02:03 PM Re: Using dos "For" command and tokens
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Ooomigosh, what on Earth is all that!

You are making things pretty hard for yourself.

Keep all the code within KiXtart, there is no need to use the DOS For command.

Use KiXtart "Split()" to break the mapping line ($x) into an array, then do the mapping in the loop rather than calling external code.

Much easier, much faster, and much less prone to error.

As for the DOS variables, "%" is a reserved metacharacter in KiXtart, so try doubling them up "%%b" -> "%%%%b"

[EDIT]
I've just noticed you have "NoVarsInStrings" on, but you have variables embedded in your strings, which is going to cause you problems.
[/EDIT]


Edited by Richard H. (2004-05-28 02:06 PM)

Top
#120364 - 2004-06-01 01:01 PM Re: Using dos "For" command and tokens
Simon Offline
Lurker

Registered: 2004-05-28
Posts: 2
Great, thanks for the quick reply. I have tried converting it into an array and it seems to work pretty well, although i'm a bit unsure about putting the elements into variables and passing them to another subroutine.
Any help with this would be appreciated
thanks
Simon

Top
#120365 - 2004-06-01 01:55 PM Re: Using dos "For" command and tokens
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Try something like this:
Code:
Dim $rc,$x
$rc=SetOption('explicit','on')
$rc=SetOption('novarsinstrings','on')

If Open(3, "deptmap.txt") = 0
$x = ReadLine(3)
While @ERROR = 0
$x = Split($x,",")
MapDrive($x[0],$x[3])
$x = ReadLine(3)
Loop
EndIf

Function MapGroupDrive($sUserGroup,$sRemoteShare)
"Mapping '"+$sRemoteShare+"' for '"+$sUserGroup+"'..."+@CRLF
; ... do mapping here ...
EndFunction


Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Henriques) and 2516 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.055 seconds in which 0.026 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org