The Execute Program

This program is similar to the program which is found here: http://www.theeasygambasdoku.de/misc/processes/exec/index.html It has been changed to run without errors in newer gambas versions.

You need 2 command buttons, 2 textareas and 1 combobox to get the program going. Rename the command buttons according to the code.

EXEC offers the possibility to execute a command via the shell. It creates an object of the class Process.

The Program

Choose or enter a program which is to be executed in the combobox and click the fire-button. The first textarea shows errors, the second feedbacks from the process.

The Code:

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