[Gambas-user] EXEC or SHELL can not READ WRITE simultaneously well with process?
Benoît Minisini
gambas at ...1...
Sun Aug 15 22:18:52 CEST 2010
> I have searched around with Google but still can not find an other problem
> like mine.
> My code below base on the Console example project of Gambas.
> I want run a process like this:
>
> PUBLIC $mainProcess AS Process
>
> PUBLIC SUB Form_Open()
>
> $mainProcess = SHELL "7z x /demo/file.7z -o/tmp" FOR READ WRITE '
> Extract /demo/file.7z to /tmp folder, same problem with EXEC
>
> END
>
> Note that I have extracted this file to /tmp before, so 7z will ask
> overwrite or not. And I want take control and answer from Gambas:
>
> PUBLIC SUB Process_Read()
>
> DIM sLine AS String
>
> LINE INPUT #$mainProcess, sLine ' I used READ #$mainProcess, sLine, -256
> too, but it break some line, and read multiple line in same moment
> txtLog.Text &= sLine & gb.newline
> IF InStr(sLine, "(Y)es / (N)o / (A)lways / (S)kip all / A(u)to rename all
> / (Q)uit?") > 0 THEN
> ' A message.question here, then print an answer like this
> PRINT #$mainProcess, "Q" ' Quit the process
> ENDIF
>
> END
>
> Also I created a button to manually response to process:
>
> PRIVATE SUB Button1_Click()
>
> PRINT #$mainProcess, "Q"
>
> END
>
> Finally, to detect program working:
>
> PUBLIC SUB Process_Kill()
>
> Message.Info("Process terminated")
>
> END
>
> My problem is, if I use FOR READ WRITE, I can't get the process output
> until process terminates (SUB Process_Read() seems not work - txtLog is
> blank). When I click the Button1, the process terminates immediately, and
> now the output appears in txtLog text box.
> If I use FOR INPUT OUTPUT, I can get the output like I want - the output
> appears in txtLog text box, (SUB Process_Read() work => PRINT "Quit"
> message to process) but process not terminates, even when I click Button1.
>
You must not use 'LINE INPUT #Process, Var' to read a process output in
Process_Read. You must use 'READ #Process, Var, -MaxLength', add 'Var' to a
'Buffer', and extract lines from that 'Buffer'.
Without a full project to test, I cannot say more at the moment.
Note that Gambas 3 is more clever than Gambas 2 for that kind of situation.
> An other small problem is from Gambas IDE. I use shortcut keys (Ctrl+C,
> Ctrl+X) to copy, cut text from Gambas Editor (when cut, the selected text
> disappears), but I can not paste anywhere, even back to Gambas editor. But
> I use the context menu, it works fine.
CTRL+V works perfectly there. Do you have more details?
--
Benoît Minisini
More information about the User
mailing list