Example: /Util/Shell

Online Documentation   -   Statistics   -   FAQ   -   Plugin Parts (All, Dependencies)   -   Class hierarchy

New in Version 22.2 22.3 22.4 22.5 23.0 23.1 23.2 23.3 23.4 23.5 24.0 24.1

The list of the   topics,   classes,   interfaces,   controls,   modules,   global methods by category,   global methods by name,   screenshots,   licenses   and   examples.

Platforms to show: All Mac Windows Linux Cross-Platform

/Util/Shell


Required plugins for this example: MBS Util Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Util/Shell

This example is the version from Sat, 3rd Mar 2023.

Project "Shell.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open() 'TestWhoami 'TestPing TestPingAsync End EventHandler
Sub TestPing() // synchronously Dim s As New ShellMBS Dim args() As String args.Append "-c" args.Append "5" args.Append "monkeybreadsoftware.com" s.SetArguments args s.Execute "/sbin/ping" Dim output As String = s.ReadOutput Dim errors As String = s.ReadError While s.IsRunning output = output + s.ReadOutput errors = errors + s.ReadError MainWindow.Log.Text = output+Errors // wait a bit app.DoEvents 1 Wend output = output + s.ReadOutput errors = errors + s.ReadError End Sub
Sub TestPingAsync() // synchronously sh = New MyShellMBS Dim args() As String args.Append "-c" args.Append "5" args.Append "monkeybreadsoftware.com" sh.SetArguments args dim AppPath as string #if TargetLinux then AppPath = "/usr/bin/ping" #ElseIf TargetWindows then AppPath = "ping.exe" #ElseIf TargetMacOS then AppPath = "/sbin/ping" #else ? #endif sh.Execute AppPath If sh.ErrorCode <> 0 Then MsgBox "Failed to run "+Str(sh.ErrorCode) End If // see evens in MyShellMBS for reading data End Sub
Sub TestWhoami() Dim s As New ShellMBS s.Execute "/usr/bin/whoami" s.Wait 5 Dim output As String = s.ReadOutput Dim errors As String = s.ReadError Break MsgBox "whoami: "+output End Sub
Property sh As MyShellMBS
End Class
Class MainWindow Inherits Window
Control Log Inherits TextArea
ControlInstance Log Inherits TextArea
End Control
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class MyShellMBS Inherits ShellMBS
EventHandler Sub Completed() output = output + Me.ReadOutput errors = errors + Me.ReadError MainWindow.Log.Text = output+Errors+EndOfLine+"ErrorCode: " + me.ErrorCode.ToString MsgBox "Completed" End EventHandler
EventHandler Sub DataAvailable(AvailableBytesError as Integer, AvailableBytesOutput as Integer) output = output + Me.ReadOutput errors = errors + Me.ReadError MainWindow.Log.Text = output+Errors End EventHandler
Property Errors As string
Property output As string
End Class
End Project

The items on this page are in the following plugins: MBS Util Plugin.


💬 Ask a question or report a problem