Created
November 28, 2022 19:57
-
-
Save jbadger3/085c37d2847819e22bd07054596c081b to your computer and use it in GitHub Desktop.
Example of creating a subprocess in Swift.
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 | |
print("PID: \(process.processIdentifier)") | |
print("stdin FD: \(standardInputFH.fileDescriptor)") | |
print("stdout FD: \(standardOutputFH.fileDescriptor)") | |
print("stderr FD: \(standardErrorFH.fileDescriptor)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment