Enable strings to run commands using themselves as standard input.

This commit is contained in:
Kare Morstol
2015-10-07 18:48:04 +02:00
parent 99df0ddf19
commit 93809fa694
2 changed files with 16 additions and 0 deletions
+12
View File
@@ -7,3 +7,15 @@
import Foundation
/** Let Strings run commands using itself as stdin. */
extension String: ShellRunnable {
public var shellcontext: ShellContextType {
var context = ShellContext(main)
let (writer,reader) = streams()
writer.write(self)
writer.close()
context.stdin = reader
return context
}
}
@@ -11,4 +11,8 @@ import SwiftShell
class String_Tests: XCTestCase {
func testRunCommands () {
XCTAssertEqual("one two".run("wc","-w"), "2")
XCTAssertEqual("one".runAsync("cat").stdout.read(), "one")
}
}