Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCF/Authorization/Authorization with Stream
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
This example is the version from Sun, 17th Mar 2012.
Project "Authorization with Stream.rbp"
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 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 End EventHandler
End Control
Control EditField3 Inherits TextArea
ControlInstance EditField3 Inherits TextArea
End Control
Sub run() dim s(0) as String dim p,t as String dim f,dir as FolderItem dim a as AuthorizationMBS dim e as integer dim b as BinaryStream dim sh as Shell 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 e=a.Wait // wait for process to terminate. Returns PID if a.LastError<>0 then MsgBox "Lasterror on Wait: "+str(a.LastError) end if end if EditField3.text=a.ReadStream(1024) end if end if end if end if 'f.Delete end if End Sub
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.

MBS Xojo Plugins