This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/swift | |
import Foundation | |
let catProcess = Process() | |
catProcess.executableURL = URL(fileURLWithPath: "/bin/cat") | |
catProcess.arguments = ["PipeExample.swift"] | |
let pipe1 = Pipe() | |
let grepProcess = Process() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/swift | |
import Foundation | |
let arguments = CommandLine.arguments | |
let startingValue = Int(arguments[1])! | |
var flush = false | |
if arguments.count == 3 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
let outputPipe = Pipe() | |
let process = Process() | |
process.executableURL = URL(fileURLWithPath:"/bin/bash") | |
process.arguments = ["-c", "ls"] | |
process.standardOutput = outputPipe | |
outputPipe.fileHandleForReading.readabilityHandler = { fileHandle in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
let outputPipe = Pipe() | |
let process = Process() | |
process.executableURL = URL(fileURLWithPath:"/bin/bash") | |
process.arguments = ["-c", "ls"] | |
process.standardOutput = outputPipe | |
try? process.run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
let outputPipe = Pipe() | |
let process = Process() | |
process.executableURL = URL(fileURLWithPath:"/bin/bash") | |
process.arguments = ["-c", "ls"] | |
process.standardOutput = outputPipe | |
outputPipe.fileHandleForReading.readabilityHandler = { fileHandle in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for try await line in FileHandle.standardOutput.bytes.lines { | |
///Do something with output | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
let process = Process() | |
process.executableURL = URL(fileURLWithPath:"/bin/bash") | |
process.arguments = ["-c", "ls"] | |
try? process.run() | |
let standardInputFH = process.standardInput as! FileHandle | |
let standardOutputFH = process.standardOutput as! FileHandle | |
let standardErrorFH = process.standardError as! FileHandle |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
let processInfo = ProcessInfo() | |
print("COMMAND: \(processInfo.processName)") | |
print("PID: \(processInfo.processIdentifier)") | |
print("USER \(processInfo.userName)") | |
print("stdin FD: \(FileHandle.standardInput.fileDescriptor)") | |
print("stdout FD: \(FileHandle.standardOutput.fileDescriptor)") | |
print("stderr FD: \(FileHandle.standardError.fileDescriptor)") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Terminus | |
let terminal = Terminal.shared | |
let lineEditor = LineEditor() | |
lineEditor.bufferHandler = { | |
var shouldWriteBuffer = false | |
if let greenRange = lineEditor.buffer.range(of: "green") { | |
lineEditor.buffer[greenRange].terminalTextAttributes = [.color(Color(r: 0, g: 255, b: 0))] | |
shouldWriteBuffer = true |
NewerOlder