Added documentation.

This commit is contained in:
Kare Morstol
2014-08-28 21:04:28 +02:00
parent 45bc5b2ae2
commit e7fb2de10b
+22 -4
View File
@@ -10,25 +10,42 @@ import Foundation
private func newtask (shellcommand: String) -> NSTask {
let task = NSTask()
task.arguments = ["-c",shellcommand]
task.arguments = ["-c", shellcommand]
task.launchPath = "/bin/bash"
// avoids implicit reading of the main script's standardInput
task.standardInput = NSPipe ()
return task
}
/**
Run a shellcommand synchronously with no standard input.
:returns: Standard output
*/
public func run (shellcommand: String) -> ReadableStreamType {
let task = newtask(shellcommand)
// avoids implicit reading of the main script's standardInput
task.standardInput = NSPipe ()
let output = NSPipe ()
task.standardOutput = output
task.launch()
// necessary for now to ensure one shellcommand is finished before another begins.
// uncontrolled asynchronous shell processes could be messy.
// but shell commands on the same line connected with the pipe operator should preferably be asynchronous.
task.waitUntilExit()
return output.fileHandleForReading
}
/**
Run a shell command synchronously.
:param: input Standard input.
:returns: Standard output
*/
public func run (shellcommand: String)(input: ReadableStreamType) -> ReadableStreamType {
let task = newtask(shellcommand)
task.standardInput = input as File
@@ -37,5 +54,6 @@ public func run (shellcommand: String)(input: ReadableStreamType) -> ReadableStr
task.standardOutput = output
task.launch()
task.waitUntilExit()
return output.fileHandleForReading
}