title: Running Swift commands from a Mac app
body: <p>I'm attempting to run a Swift script using the command line from my Swift-based Mac app.</p>
  
  <p>I have the following class method, which takes in arguments, and runs the commands:</p>
  
  <pre><code>func shell(_ args: String...) -&gt; Int32 {
      let task = Process()
      task.launchPath = "/usr/bin/env"
      task.arguments = args
      task.launch()
      task.waitUntilExit()
      return task.terminationStatus
  }
  </code></pre>
  
  <p>I'm able to execute commands such as the following successfully:</p>
  
  <pre><code>    shell("pwd")
      shell("ls")
      shell("swift")
  </code></pre>
  
  <p><code>pwd</code> returns all the files in my app's build directory, as expected. This includes a <code>hello.swift</code> file that I manually added, which just prints "Hello, world!". Additionally, running <code>swift</code> does grant access to the Swift environment. </p>
  
  <p>What I'm not having luck with is running commands such as:</p>
  
  <p><code>shell("swiftc hello.swift")</code> </p>
  
  <p>Instead, I get the following error:</p>
  
  <p><code>env: swiftc hello.swift: No such file or directory</code></p>
  
  <p>It looks as though I'm facing a similar situation as these posts:</p>
  
  <p><a href="https://stackoverflow.com/questions/43266759/swift-process-execute-command-error">Swift Process - execute command error</a></p>
  
  <p><a href="https://stackoverflow.com/questions/32238366/running-shell-commands-in-swift?rq=1">Running shell commands in Swift</a></p>
  
  <p>But, I'm not sure I fully understand all the implications therein for my specific situation. </p>