Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCF/Authorization/Authorization with Stream Async
Function:
Required plugins for this example: MBS MacCF Plugin, MBS MacOSX Plugin, MBS Util Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCF/Authorization/Authorization with Stream Async
This example is the version from Sun, 17th Mar 2012.
Project "Authorization with Stream Async.rbp"
FileTypes
Filetype text
End FileTypes
Class Window1 Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() Run End EventHandler
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control EditField1 Inherits TextField
ControlInstance EditField1 Inherits TextField
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
Control StaticText3 Inherits Label
ControlInstance StaticText3 Inherits Label
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action() if a<>nil then EditField3.text=EditField3.text+a.ReadStream(1024) end if End EventHandler
End Control
Control EditField2 Inherits TextArea
ControlInstance EditField2 Inherits TextArea
EventHandler Sub Open() me.text="#! /bin/sh"+endofline+ _ ""+endofline+ _ "echo Hello World!"+endofline+ _ ""+endofline+ _ "echo passed from Realbasic: $@"+endofline+ _ ""+endofline+ _ "#"+endofline+ _ "# print the user name:"+endofline+ _ "#"+endofline+ _ "whoami"+endofline+ _ "#"+endofline+ _ "# should be root"+endofline+ _ "#"+endofline+ _ "ping -c 10 localhost"+endofline End EventHandler
End Control
Control EditField3 Inherits TextArea
ControlInstance EditField3 Inherits TextArea
End Control
EventHandler Sub Close() Stop End EventHandler
Protected Sub Stop() if a<>nil then a=nil end if End Sub
Sub run() dim s(0) as String dim p,t as String dim f,dir as FolderItem dim e as integer dim b as BinaryStream dim sh as Shell Stop s(0)=ConvertEncoding(EditField1.text,Encodings.UTF8) // write shell script file: dir=CreateApplicationSupportFolderMBS(-32763) if dir=nil then MsgBox "Missing Application Support folder in user directory." else f=dir.Child("TestScript") b=f.CreateBinaryFile("text") if b=nil then MsgBox "Failed to create script file." else t=ConvertEncoding(EditField2.text,Encodings.UTF8) t=ReplaceAll(t,EndOfLine.Macintosh,EndOfLine.UNIX) // line encodings are very important to avoid error -60031 b.Write t MsgBox t b.Close b=nil p=f.UnixpathMBS if p="" then MsgBox "Can't find the path to my script." else sh=new Shell sh.Execute "chmod 777 "+f.ShellPath if sh.ErrorCode<>0 then MsgBox "Failed to set permissions. "+str(sh.ErrorCode) else a=new AuthorizationMBS if a.SimpleNewAuthorization then // create a.Execute(p,s,true) // and run it if a.LastError<>0 then MsgBox "Lasterror on Execute: "+str(a.LastError) else a.MakeStreamAsyncron end if end if end if end if end if 'f.Delete end if End Sub
Property Protected a As AuthorizationMBS
End Class
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
End Class
End Project

See also:

Feedback, Comments & Corrections

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




Links
MBS Xojo Plugins