User Tools

Site Tools


k21:k21.3:k21.3.4:start

21.3.4 Project - 'Ping'

The project 'ping_p' supplements the explanations in chapter 21.3.1 for example 3. While the quick syntax of the instructions SHELL and EXEC was used in the mentioned example project, now the started process is observed and data is read and displayed both from the standard output and from the standard error output of the process. Data is not passed to the process because the 'ping' programme is not an interactive programme. The active process can be terminated. This is also shown in the project.

ping1
Figure 21.3.4.1: GUI design for the programme 'ping' - programme terminated.

In Figure 21.3.4.1 you can see the complete data from the standard output of the process after the regular termination of the external console program 'ping' after exactly 7 pings and an inserted notification. As long as the started process is active, the incoming response data is output asynchronously one after the other:

ping2
Figure 21.3.4.2: GUI design for the programme 'ping' - programme at runtime

Process error outputs are detected in the presented project with the minimum set parameters already at the start of the process and output formatted in an error message:

URL: www.gambas-buch.de
Count: -4

PROCESS ERROR!
ping: bad number of packets to transmit.

Return value from program 'ping' = 2
The process with the PID = 3423 was terminated normally.

URL: www.gambas+buch.de
Count: 4

PROCESS ERROR!
ping: unknown host www.gambas+buch.de

Return value from program 'ping' =  2
The process with the PID = 3970 was terminated normally.

If one terminates the started process with the method $hPing.Kill() - triggered by a click on the button with the label K - then the event Kill is recognised and handled, formatted and displayed in the event handler myPingProcess_Kill():

Return value from program 'ping' =  9
The process with the PID = 3984 was terminated! (SIGKILL)

Source code of the relevant procedures:

Public Sub btnProcessKill_Click()
 
  If $hPing Then $hPing.Kill()
  ' Alternative über System-Aufruf:
  ' If $hPing Then Shell "kill -s 9 " & $hPing.Id
  ' Endif ' $hPing existiert ?
  txaOutput.Foreground = Color.Red
  txaOutput.Clear
 
End ' btnProcessKill_Click()
 
Public Sub myPingProcess_Kill()
  txaOutput.Insert(gb.NewLine)
  txaOutput.Insert("Rückgabewert '" & sProgrammName & "' =  " & $hPing.Value & gb.NewLine)
 
  Select Case $hPing.State
  Case 0
    txaOutput.Insert("Prozess (PID = " & $hPing.Id & " ) wurde normal beendet." & gb.NewLine)
  Case 1
    txaOutput.Insert("Prozess (PID = " & $hPing.Id & " ) wurde gestoppt!" & gb.NewLine)
  Case 2
    txaOutput.Insert("Prozess (PID = " & $hPing.Id & " ) beendet! (SIGKILL)" & gb.NewLine)
  End Select ' $hProcess.State
 
  SetLEDColor("red")
  FMain.Text = "PROGRAMM PING"
  btnProcessKill.Enabled = False
  btnPingProcessStart.Enabled = True
End ' hPing_Kill()

The full source code can be found in the download section of the Gambas project.

Download

Project

Download

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k21/k21.3/k21.3.4/start.txt · Last modified: 23.10.2023 by emma

Page Tools