[Gambas-devel] Process Stream (all 64-bit Revision)

Benoit Minisini gambas at ...1...
Sun Jan 27 22:22:00 CET 2008


On dimanche 27 janvier 2008, scatman wrote:
> Hello,
>
>
> i think i have found a nother Bug
>
> I am write a little Phone-app...
>
> #### Code for Reading from phone. ####
>
> PUBLIC SUB treeViewOK_Click()
>
> SELECT CASE treeView1.Key
>
>   CASE "Save" 'save the Contact to disk
>     saveTelNr()
>
>   CASE "SM" 'read phonememory from phone
>     ColumnView1.Clear
>     $hProcess = EXEC ["gammu", "--getmemory", "SM", "1", "150",
> "-nonempty"] FOR READ WRITE
>     object.Attach($hProcess, ME, "Contact")
>
> End
>
> #### Code to Sort the Entries. ####
>
> PUBLIC SUB Contact_Read()
>
> ' load via exec gammu --getmemory the Contact
>
> DIM Name AS String
> DIM memory AS String
> DIM location AS String
> DIM entrie AS Integer
>
> WHILE NOT Eof(LAST)
>   LINE INPUT #LAST, PhoneData
>
>     ' PhoneData = Conv(PhoneData, system.Charset, desktop.Charset)
>
>     PRINT PhoneData
>
>     IF Mid$(PhoneData, 12, 8) = "Location" THEN
>       location = Right$(PhoneData, 2)
>     END IF
>
>     IF Left$(PhoneData, 4) = "Name" THEN
>       name = Mid$(PhoneData, InStr(PhoneData, ":") + 3, - 1)
>     END IF
>
>     IF Left$(PhoneData, 7) = "General" THEN
>       number = Mid$(PhoneData, (InStr(PhoneData, ":")) + 3, -1)
>     END IF
>
>     IF Left$(PhoneData, 6) = "Memory" THEN
>       memory = Mid$(PhoneData, (InStr(PhoneData, "Memory")) + 7, 2)
>     END IF
>
>      IF location <> NULL THEN
>      IF entrie <> Val(location) THEN
>        ColumnView1.Add(Val(location), name)
>        Columnview1[Val(location)][1] = number
>        ColumnView1[Val(location)][2] = memory
>        ColumnView1[Val(location)][3] = location
>        label6.Text = Index
>        entrie = Val(location)
>      END IF
>      END IF
>
> WEND
>
> END
>
>
> Now my Problem.
> The Stream is Broken.
>
> #### gammu via console gives me this ###
>
> Memory ME, Location 1
> General number       : "+4912345678"
> Name                 : "Mr. Mustermann/M"
>
> Memory ME, Location 2
> General number       : "012345678"
> Name                 : "Firma/W"
>
> and so on.
>
>
> the Stream inside Gambas looks
>
> Memory ME, Location 1
> number       : "+4912345678"
> Name                 : "Mr. Mustermann/M"
>
> Memory ME, Location 2
> General number       : "012345678"
> Name                 : "Firma/W"
>
> But every 10 Locations the Stream is Broken
>
> Memory ME, Location 11
> General number
>
>    : "+4923456789"
>
> Name                 : "DIETER/M"
>
> from 12 to 20 is everything OK.
>
> Memory ME, Location 21
> General number       : "+49000000000"
> Name
>
>        : "M. Rosenberg/H"
>
> If you need my Project, i can send it.
>
> thanks
>

Beware! 

When you use LINE INPUT, you read a line that is ended by an "end-of-line" 
character, or by the end of the stream. In other words, LINE INPUT does not 
block until an end-of-line is reached. Maybe I should make a property for 
that in the Stream class, but I don't at the moment.

During the call to Contact_Read, not the entire output of the process is 
available, so you could get part of a line.

To know if you really read a full line, or if you reached the end of the 
stream because the running process did not send all its data yet, you must 
use the Process.EndOfFile property. See the documentation of this property 
for more details.

Regards,

-- 
Benoit Minisini




More information about the Devel mailing list