Phạm Quang Dương
2010-08-15 20:09:46 UTC
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
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
Also I created a button to manually response to process:
PRIVATE SUB Button1_Click()
PRINT #$mainProcess, "Q"
Finally, to detect program working:
PUBLIC SUB Process_Kill()
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.
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.
My Gambas version is 2.20 (full is 2.20.2-1.fc13.i686) on Fedora 13. My
machiine is DELL Inspiron 1440 (Pen Dual Core).
Thank for answers. Sorry for my English.