diff --git a/SwiftShell/Command.swift b/SwiftShell/Command.swift index 2ccfe16..a6c53bc 100644 --- a/SwiftShell/Command.swift +++ b/SwiftShell/Command.swift @@ -65,9 +65,9 @@ extension ShellRunnable { task.environment = shellcontext.env task.currentDirectoryPath = shellcontext.currentdirectory - task.standardInput = shellcontext.stdin + task.standardInput = shellcontext.stdin.filehandle task.standardOutput = shellcontext.stdout.filehandle - task.standardError = shellcontext.stderror + task.standardError = shellcontext.stderror.filehandle return task } diff --git a/SwiftShell/Context.swift b/SwiftShell/Context.swift index dfdb1c9..d5a91cd 100644 --- a/SwiftShell/Context.swift +++ b/SwiftShell/Context.swift @@ -11,9 +11,9 @@ public protocol ShellContextType { var encoding: NSStringEncoding {get set} var env: [String: String] {get set} - var stdin: NSFileHandle {get set} + var stdin: ReadableStream {get set} var stdout: WriteableStream {get set} - var stderror: NSFileHandle {get set} + var stderror: WriteableStream {get set} /** The current working directory. @@ -29,9 +29,9 @@ public struct ShellContext: ShellContextType { public var encoding: NSStringEncoding public var env: [String: String] - public var stdin: NSFileHandle + public var stdin: ReadableStream public var stdout: WriteableStream - public var stderror: NSFileHandle + public var stderror: WriteableStream /** The current working directory. @@ -46,9 +46,9 @@ public struct ShellContext: ShellContextType { encoding = NSUTF8StringEncoding env = [String:String]() - stdin = NSFileHandle.fileHandleWithNullDevice() + stdin = ReadableStream(NSFileHandle.fileHandleWithNullDevice(), encoding: encoding) stdout = WriteableStream(NSFileHandle.fileHandleWithNullDevice(), encoding: encoding) - stderror = NSFileHandle.fileHandleWithNullDevice() + stderror = WriteableStream(NSFileHandle.fileHandleWithNullDevice(), encoding: encoding) currentdirectory = main.currentdirectory } @@ -77,9 +77,9 @@ public final class MainShellContext: ShellContextType { public var encoding = NSUTF8StringEncoding public lazy var env = NSProcessInfo.processInfo().environment as [String: String] - public lazy var stdin = NSFileHandle.fileHandleWithStandardInput() //as ReadableStreamType + public lazy var stdin: ReadableStream = { ReadableStream(NSFileHandle.fileHandleWithStandardInput(), encoding: self.encoding) }() public lazy var stdout: WriteableStream = { WriteableStream(NSFileHandle.fileHandleWithStandardOutput(), encoding: self.encoding) }() - public lazy var stderror = NSFileHandle.fileHandleWithStandardError() //as WriteableStreamType + public lazy var stderror: WriteableStream = { WriteableStream(NSFileHandle.fileHandleWithStandardError(), encoding: self.encoding) }() /** The current working directory. diff --git a/SwiftShellTests/Command_Tests.swift b/SwiftShellTests/Command_Tests.swift index fd09072..46fb71d 100644 --- a/SwiftShellTests/Command_Tests.swift +++ b/SwiftShellTests/Command_Tests.swift @@ -78,7 +78,7 @@ class RunAndPrint_Tests: XCTestCase { test_stdout = outputpipe.fileHandleForReading let errorpipe = NSPipe() - main.stderror = errorpipe.fileHandleForWriting + main.stderror = WriteableStream(errorpipe.fileHandleForWriting) test_stderr = errorpipe.fileHandleForReading } diff --git a/SwiftShellTests/Context_Tests.swift b/SwiftShellTests/Context_Tests.swift index 2df5eef..b4b78b8 100644 --- a/SwiftShellTests/Context_Tests.swift +++ b/SwiftShellTests/Context_Tests.swift @@ -58,9 +58,9 @@ class BlankShellContext_Tests: XCTestCase { func testIsBlank () { let context = ShellContext() - XCTAssert( context.stdin === NSFileHandle.fileHandleWithNullDevice() ) + XCTAssert( context.stdin.filehandle === NSFileHandle.fileHandleWithNullDevice() ) XCTAssert( context.stdout.filehandle === NSFileHandle.fileHandleWithNullDevice() ) - XCTAssert( context.stderror === NSFileHandle.fileHandleWithNullDevice() ) + XCTAssert( context.stderror.filehandle === NSFileHandle.fileHandleWithNullDevice() ) } func testNonAbsoluteExecutablePathFailsOnEmptyPATHEnvVariable () {