Skip to content

Commit

Permalink
Stream shell output
Browse files Browse the repository at this point in the history
make it so that the terminal output window `Tools > Terminal Output`
will receive streams of messages from scripts that are running

resolves #1
  • Loading branch information
muandrew committed Feb 28, 2019
1 parent 44397f1 commit 7dffa08
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions AndroidTool/ShellTasker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,10 @@ class ShellTasker: NSObject {
isUserScript:Bool = false,
isIOS:Bool = false,
complete:@escaping (_ output:NSString)-> Void) {
var output = NSString()
var data = Data()

var scriptPath:String

if isUserScript {
scriptPath = scriptFile
} else {
scriptPath = Bundle.main.path(forResource: scriptFile, ofType: "sh")!
}

let scriptPath = isUserScript
? scriptFile
: Bundle.main.path(forResource: scriptFile, ofType: "sh")!
let resourcesPath = Bundle.main.resourcePath!

task = Process()
Expand Down Expand Up @@ -96,8 +89,8 @@ class ShellTasker: NSObject {
queue: nil)
{ (notification) -> Void in
DispatchQueue.global(priority: DispatchQueue.GlobalQueuePriority.default).async(execute: { () -> Void in
data = pipe.fileHandleForReading.readDataToEndOfFile() // use .availabledata instead to stream from the console, pretty cool
output = NSString(data: data, encoding: String.Encoding.utf8.rawValue)!
let data = pipe.fileHandleForReading.availableData
let output = NSString(data: data, encoding: String.Encoding.utf8.rawValue)!
DispatchQueue.main.async(execute: { () -> Void in
self.postNotification(output, channel: self.notificationChannel())
complete(output)
Expand Down

0 comments on commit 7dffa08

Please sign in to comment.