[Gambas-user] SHELL is more faster than SUB Process_Read()
Benoît Minisini
gambas at ...1...
Sun Aug 15 22:24:56 CEST 2010
> Hi i wrote a test program that "ls -1" a directory with 1700 and more files
> (mp3).
>
> i wanted to make a string as following
>
> Content = "/mnt/store/MUSIC/free/new age/webradio recs/Trancemission.FM
> Radio 128K- New Age 2- new experience of meditation and new age music -
> livestream 128k/" & sLine
>
> in order to list with full path the files.
>
> but i dont get the wanted result.
>
>
> The SHELL command runs faster than Process_Read.
>
> This mess up the result of concatenation.
>
> The code is the following:
>
> ---------------------------------------------------------------------------
> ----- ' Gambas class file
>
> PUBLIC SUB Button1_Click()
> SHELL "ls -1 \'/mnt/store/MUSIC/free/new age/webradio
> recs/Trancemission.FM Radio 128K- New Age 2- new experience of meditation
> and new age music - livestream 128k/\'" FOR READ
>
> END
>
> PUBLIC SUB Process_Read()
>
> DIM sLine AS String
> DIM Content AS String
>
> ' IF Eof(LAST) THEN RETURN
>
> READ #LAST, sLine
That line is not correct, because you are reading the string from the stream
in the internal Gambas format (length stored in one, two or four bytes,
followed by the string contents), whereas the process just send characters on
its standard output. See the documentation on READ for more details.
You must do that to read the standard output of a process:
PRIVATE $sBuffer AS String
PUBLIC SUB Process_Read()
READ #LAST, sData, Lof(#LAST)
$sBuffer &= sData
DO
iPos = Instr($sBuffer, "\n")
IF iPos = 0 THEN BREAK
sLine = Left($sBuffer, iPos - 1)
$sBuffer = Mid$($sBuffer, iPos + 1)
' Do what you need with sLine
LOOP
END
Regards,
--
Benoît Minisini
More information about the User
mailing list