title: Swift Terminal Emulator: errors in complex commands
body: <p>I'm trying to create a Terminal Emulator using Swift and so far I've gotten all the basic functionality. I can send commands like <code>diskutil list</code> and get their correct output. But if I require the program to be interactive in anyway such as <code>sudo reboot</code> where the user must specify their password, I get the error <code>sudo: no tty present and no askpass program specified</code>; or perhaps when I want to use <code>nano anyTextFile.txt</code>, I'll get an error like <code>Error opening terminal: unknown.</code> I don't see anything within the <code>Process</code> class that has anything to do with specifying a TTY or an askpass (whatever that is)</p>
  
  <p>Here's my code that should be relevant to this question:</p>
  
  <pre><code>func shell(_ args: String) -&gt; (output: [String], error: [String], exitCode: Int32) {
      var output : [String] = []
      var error : [String] = []
  
  
      let task = Process()
      task.launchPath = "/usr/bin/env"
      let cmd = args.characters.split(separator: " ").map(String.init)
      task.arguments = cmd
  
      let outpipe = Pipe()
      task.standardOutput = outpipe
      let errpipe = Pipe()
      task.standardError = errpipe
  
      task.launch()
  
      let outdata = outpipe.fileHandleForReading.readDataToEndOfFile()
      if var string = String(data: outdata, encoding: .utf8) {
          string = string.trimmingCharacters(in: .newlines)
          output = string.components(separatedBy: "\n")
      }
  
      let errdata = errpipe.fileHandleForReading.readDataToEndOfFile()
      if var string = String(data: errdata, encoding: .utf8) {
          string = string.trimmingCharacters(in: .newlines)
          error = string.components(separatedBy: "\n")
      }
  
      task.waitUntilExit()
      let status = task.terminationStatus
  
      return (output, error, status)
  }
  </code></pre>