[Gambas-user] Problem with the EXEC[] function
Benoit Minisini
gambas at ...1...
Mon Mar 7 16:41:32 CET 2005
On Monday 07 March 2005 16:30, Rolf Schmidt wrote:
> Thank you Benoit Minisini:
> > > PUBLIC DBisCreated AS Boolean
> > >
> > > PUBLIC SUB Process_Read()
> > > DIM sline AS String
> > >
> > > LINE INPUT #LAST, sline
> > > ' message.Info(sline)
> > >
> > > returndata = returndata & sline
> > > IF sline = "CREATE DATABASE" THEN
> > > DBisCreated = TRUE
> > > ELSE
> > > DBisCreated = FALSE
> > > ENDIF
> > > END
> > >
> > > PUBLIC FUNCTION createDB() AS Boolean
> > > CAskDB.ShowModal()
> > > EXEC ["createdb", "-h", FHV.konfig.Key("host"), "-U",
> > > FHV.konfig.Key("user"), "-E", "UNICODE",
> > > FHV.konfig.Key("database")] WAIT FOR READ
> > > ' why is the flag always false?
> > > IF DBisCreated = TRUE THEN
> > > EXEC ["psql", "-h", FHV.konfig.Key("host"), "-u",
> > > FHV.konfig.Key("user"), "-d", FHV.konfig.Key("database"), "-f",
> > > "/home/entwicklung/hausverwaltung/HV/pgdatabase"] WAIT FOR
> > > READ ' why does this function never comes back - could it be, that it
> > > sends some ' informations via the error chanel? - How can I fetch these
> > > too? ENDIF
> > > END
> >
> > This is a problem in the process management of Gambas. You must not use
> > WAIT if you want to use FOR READ/WRITE, because the event loop is not
> > called.
>
> But without the WAIT statement the flag will never be TRUE.
You must wait by yourself:
DIM hProcess AS Process
EXEC ["createdb", "-h", FHV.konfig.Key("host"), "-U",
FHV.konfig.Key("user"), "-E", "UNICODE",
FHV.konfig.Key("database")] WAIT FOR READ AS hProcess
WHILE hProcess.State = hProcess.Running
WAIT 0.1
WEND
But this is not a clean way. A better way is to manage everything around the
top event loop: running the first process in Form_Load, for example, and
running the second process in Process_Kill() when the first is terminated.
Another point: at the moment, you cannot manage completely programs that need
to be run in a terminal (like /bin/sh, or telnet).
Regards,
--
Benoit Minisini
mailto:gambas at ...1...
More information about the User
mailing list