Выполнение программы

Эта программа похожа на программу, которая находится здесь: http://www.theeasygambasdoku.de/misc/processes/exec/index.html Она была изменена, чтобы запускаться без ошибок в новых версиях gambas.

Вам нужно 2 управляющие клавиши, 2 тестовые области и 1 комбинированную панель (combobox), чтобы получить работающую программу. Переименуйте клавиши управления согласно с кодом.

EXEC предполагает возможность выполнения команды через терминал (shell). Создается объект класса Process.

Программа

Выберите или введите программу, которая должна выполняться в комбинированной панели (combobox) и щелкните по клавише запуска (fire-button). Первая текстовая область покажет ошибки, вторая возврат из процесса. 

Код:

Gambas class file

PRIVATE myProcess AS Process

'------------------------------------------------
STATIC PUBLIC SUB Main()
DIM hForm AS Form
hForm = NEW FMain
hForm.Show()
END

'------------------------------------------------
PUBLIC SUB _new()
ME.Title = "Working with the command EXEC"
ComboBox1.add("kate")
ComboBox1.add("")
ComboBox1.add("kiconedit")
ComboBox1.add("gimp")

' the programs must be installed!
END

'------------------------------------------------
' start it
PUBLIC SUB btnFire_Click()
IF Trim(ComboBox1.Text) <> "" THEN

'Trim strips the whitespaces from a string
TextArea1.Text = ""
TextArea2.Text = ""

' call it
EXEC [ComboBox1.Text] FOR READ WRITE AS myProcess
ELSE
TextArea1.Text = "Choose or enter a program !"
ENDIF
END

'-------------------------------------------------------------
PUBLIC SUB btnClose_Click()
ME.Close()
END


'------------------------------------------------
' if something is coming back
' the event 'Process.Write' of the class process calls this function
PUBLIC SUB Process_Write(sData AS String)
TextArea2.Text = " Process '" & myProcess.command & "' " & sData
END

'------------------------------------------------
' if an error occurrs
' the event 'Process.Error' of the class process calls this function
PUBLIC SUB Process_Error(sData AS String)
TextArea1.Text = " Process '" & myProcess.command & "' " & sData
END

'------------------------------------------------
' if the process is killed
' the event 'Process.Kill' of the class process calls this function
PUBLIC SUB Process_Kill()
myProcess = NULL
END




-- ReinerHoffmann - 10 Sep 2004