title: How to execute terminal commands in Swift 4?
body: <p>I have an iOS app and in the unit tests (XCTests) I need to execute some terminal commands such as
  <code>xcrun simctl shutdown [simulator-UDID]</code></p>
  
  <p>I created this function to run the shell scripts</p>
  
  <pre><code>func commandLine(launchPath: String, arguments: [String]) -&gt; String {
      // Used to be NSTask() before Swift 3
      let process = Process()
  
      // Set the task parameters
      process.launchPath = "/usr/bin/env"
      process.arguments = ["pwd"]
  
      // Create a Pipe and make the process
      // put all the output there
      let pipe = Pipe()
      process.standardOutput = pipe
  
      // Launch the process
      process.launch()
  
      // Get the data
      let data = pipe.fileHandleForReading.readDataToEndOfFile()
      let output = NSString(data: data, encoding: NSUTF8StringEncoding)
  
      print(output!)
  }
  </code></pre>
  
  <p>However, I got the error saying that </p>
  
  <blockquote>
    <p>Use of unresolved identifier 'Process'</p>
  </blockquote>
  
  <p>Did some research and it turns out <code>Process()</code> has been renamed to <code>CommandLine</code> in Swift 4, but changing to <code>CommandLine</code> causes different error </p>
  
  <blockquote>
    <p>'CommandLine' cannot be constructed because it has no accessible initializers</p>
  </blockquote>