Page 1 of 1 1
Topic Options
#122992 - 2004-07-15 11:36 AM split into array doesn't work when value is quoted
Grutte Pier Offline
Getting the hang of it

Registered: 2001-10-06
Posts: 52
Loc: Leeuwarden, The Netherlands
Hello,

In my script (see below) I try cleanup the autoexec.bat of Win98 machines. First I read line by line the autoexec and write those lines that do not contain the word "path" to an new file. All goes wel in this part. Then I read the system variable %path% and split it based on the separator ";" and put the value's in to an array. The values within the array are checked and if they match they my conditions they will be written to the new autoexec file.
This works unless the path segment value, between the ";" seperators, is quoted.
I like the script to work for those parts as well.
Then

Case based on the fact that oracle is installed in C:\oracle:
If the old sitiuation =
Path="C:\test1";c:\test2;C:\oracle\bin;C:\windows\system

The result based on this script is now:

Path=c:\test2;C:\windows\system

Desired result should be:

Set Path="C:\test1";c:\test2;C:\windows\system

Used script:
Code:

Function WshPipe($ShellCMD, OPTIONAL $NoEcho)
Dim $oExec, $Output
$oExec = CreateObject("WScript.Shell").Exec($ShellCMD)
If NOT VarType($oExec)=9 $WshPipe="WScript.Shell Exec Unsupported" Exit 10 EndIf
While NOT $oExec.Status Loop
$Output = $oExec.StdOut.ReadAll + $oExec.StdErr.ReadAll
If NOT $NoEcho $Output EndIf
$WshPipe=Split($Output,Chr(10))
Exit($oExec.ExitCode)
EndFunction

Break On
$autoexec = "C:\autoexec.bak"
$newautoexec = "C:\autoexec.new"
$regkey = "HKEY_LOCAL_MACHINE\Software\Oracle"
If KeyExist ($regkey)
$ORAhome = ReadValue ($regkey, "ORACLE_HOME")
$sElement=Split($ORAhome,"\")
If $sElement[0]="C:"
DelTree ($regkey)
Shell '%COMSPEC% /C deltree /y $ORAhome'
If Open(1,$autoexec) = 0
While @ERROR = 0
$record = ReadLine(1)
If NOT @error
If $record
If NOT InStr($record,Path)
? $record
$ = Open(3,$newautoexec,5)
$ = WriteLine(3,$record + Chr(13) + Chr(10) )
EndIf
EndIf
EndIf
Loop
$ = WriteLine(3,"Set Path = ")
EndIf
$segment = Split("%path%",";")
For $i = 0 To Ubound($segment)
? $segment[$i]
If NOT InStr($segment[$i],$ORAhome)
$ = WriteLine(3,$segment[$i])
$ = WriteLine(3,";")
EndIf
Next
EndIf
EndIf
$ = Close(3)
:END
? ? Exit



Thanks

Top
#122993 - 2004-07-15 12:00 PM Re: split into array doesn't work when value is quoted
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
not really sure what's going on there but 2 things.
first, you don't use the wshpipe so why do you include it?

secondly, instead of parsing the path and writing it to file, you could do something like:
Code:

$segment = Split(%path%,$ORAhome)
For $i = 0 To Ubound($segment)
$path=$path+substr($segment[$i],instr($segment[$i],";")+1)
Next
set "path="+$path



totally different approach, I know.
just wanted to write some code
_________________________
!

download KiXnet

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.051 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