   var wasSuccessful: Bool {
     return exitCode == 0
   }
+}
+
+internal func runCore(_ executable: URL, _ arguments: [String] = [])
+    -> ProcessResult {
+  let stdoutPipe = Pipe()
+  var stdoutData = Data()
+  stdoutPipe.fileHandleForReading.readabilityHandler = { file in
+    stdoutData.append(file.availableData)
+  }
+
+  let stderrPipe = Pipe()
+  var stderrData = Data()
+  stderrPipe.fileHandleForReading.readabilityHandler = { file in
+    stderrData.append(file.availableData)
+  }
+
+  let process = Process()
+  process.terminationHandler = { process in
+    stdoutPipe.fileHandleForReading.readabilityHandler = nil
+    stderrPipe.fileHandleForReading.readabilityHandler = nil
+  }
+  process.launchPath = executable.path
+  process.arguments = arguments
+  process.standardOutput = stdoutPipe
+  process.standardError = stderrPipe
+  process.launch()
+  process.waitUntilExit()
+
+  return ProcessResult(exitCode: Int(process.terminationStatus),
+                       stdoutData: stdoutData,
+                       stderrData: stderrData)
 }
 
 /// Runs the provided executable with the provided arguments and returns the

///            or executable. If unable to find the appropriate object, returns
///            `nil`.
func findFirstObjectFile(for dsohandle: UnsafeRawPointer = #dsohandle) -> URL? {
  var info = dl_info()
  if dladdr(dsohandle, &info) == 0 {
    return nil
  }

///   - arguments: A list of strings to pass to the process as arguments.
/// - Returns: A ProcessResult containing stdout, stderr, and the exit code.
func run(_ executable: URL, arguments: [String] = []) -> ProcessResult {
#if _runtime(_ObjC)
  // Use an autoreleasepool to prevent memory- and file-descriptor leaks.
  return autoreleasepool { () -> ProcessResult in
    runCore(executable, arguments)
  }
#else
  return runCore(executable, arguments)
#endif
}

/// Finds the dylib or executable which the provided address falls in.
