Using Cocoa and MacRuby, use NSTask. An example that produces the output of ls -la and prints:
framework 'Cocoa'
task = NSTask.alloc.init
task.setLaunchPath("/bin/ls")
arguments = NSArray.arrayWithObjects("-l", "-a", nil)
task.setArguments(arguments)
pipe = NSPipe.pipe
task.setStandardOutput(pipe)
file = pipe.fileHandleForReading
task.launch
data = file.readDataToEndOfFile
string = NSString.alloc.initWithData(data, encoding: NSUTF8StringEncoding)
puts "Command returned: "
puts string
Unfortunately, including administrator privileges there is no trivial task, especially using MacRuby. Take a look at the SecurityFoundation infrastructure and link. Essentially you need to call
AuthorizationExecuteWithPrivileges(...)
with the configured AuthorizationRef parameter, the way the tool is executed, flags, arguments. Here's a useful example here (in ObjC) showing how this works.
source
share