Enable strings to run commands using themselves as standard input.
This commit is contained in:
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user