From cecf62fdda161b978fe7bc103c096aa0ef4c5116 Mon Sep 17 00:00:00 2001 From: Kare Morstol Date: Thu, 28 Aug 2014 00:33:06 +0200 Subject: [PATCH] Make sure a command is finished before the next begins. --- SwiftShell/Command.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/SwiftShell/Command.swift b/SwiftShell/Command.swift index 9dafb69..b8052a5 100644 --- a/SwiftShell/Command.swift +++ b/SwiftShell/Command.swift @@ -12,24 +12,30 @@ private func newtask (shellcommand: String) -> NSTask { let task = NSTask() task.arguments = ["-c",shellcommand] task.launchPath = "/bin/bash" - task.standardInput = NSPipe ()// to avoid implicit reading of the script's standardInput + + // avoids implicit reading of the main script's standardInput + task.standardInput = NSPipe () return task } public func run (shellcommand: String) -> ReadableStreamType { let task = newtask(shellcommand) + let output = NSPipe () task.standardOutput = output task.launch() + task.waitUntilExit() return output.fileHandleForReading } public func run (shellcommand: String)(input: ReadableStreamType) -> ReadableStreamType { let task = newtask(shellcommand) task.standardInput = input as File + let output = NSPipe () task.standardOutput = output task.launch() + task.waitUntilExit() return output.fileHandleForReading }