Skip to content

Instantly share code, notes, and snippets.

@bubudrc
Forked from Seasons7/nstask.swift
Created July 15, 2020 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bubudrc/4bfb364ea27c8c376ee56144c95b0f2b to your computer and use it in GitHub Desktop.
Save bubudrc/4bfb364ea27c8c376ee56144c95b0f2b to your computer and use it in GitHub Desktop.
NSTask Sample for Swift
import Cocoa
import Foundation
var str = "Hello, playground"
var task:NSTask = NSTask()
var pipe:NSPipe = NSPipe()
task.launchPath = "/bin/ls"
task.arguments = ["-la"]
task.standardOutput = pipe
task.launch()
var handle = pipe.fileHandleForReading
var data = handle.readDataToEndOfFile()
var result_s = NSString(data: data, encoding: NSUTF8StringEncoding)
print(result_s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment