Call Unix function from REALBasic

gmbaxter used Ask the Experts™

I'm trying to call a unix function from a realbasic application - the app is not really an Application, but just a screen to display an acceptable use policy with 2 buttons - agree and disagree.

button 1 - " i agree" I have an action on mouse-down for the application to quit by simply using the code "quit"

button 2 - "i disagree" This is the button i am having trouble with. Here is the code:

(on MouseDown)
dim s as new Shell
s.Execute "shutdown -r"

Under RealBasic 4.0.1 i cannot use "new Shell" just "Shell" but upon clicking the button after building the application I get "An exception of class NilObjectException was not handled. The application must shut down".

RealBasic 2009 Release 5.1 allows me to use the "new Shell" syntax but when testing, nothing happens when the button is clicked.

Any ideas?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ok sorted it myself,

realbasic 4 cannot handle the declaration in one go, so;

dim s as shell
s = new shell
s.Execute "shutdown -r"

This compiled but the button didn't do anything. This is because the current user was not a super user so could not call shutdown. solved by using sudo and tagging password into code

dim s as shell
s = new shell
s.Execute "echo password | sudo -S shutdown -r"

This achieved the required result.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial