title: Getting input from stdin in a Cocoa command-line app's sub process
body: <p>I have a command-line app <code>A</code>, and in <code>A</code> I execute an executable script <code>B</code>, in <code>B</code> I'm expecting an input from stdin.</p>
  
  <p>I wrote a demo, implementing <code>A</code> in Swift, using <code>Foundation</code>'s <code>Process</code> api, finding that <code>B</code>, no matter implemented in whatever language, cannot get user input from stdin.</p>
  
  <p>Code:</p>
  
  <pre><code>// `A`'s main.swift
  import Foundation
  let process = Process()
  process.launchPath = PATH_TO_SCRIPT_B
  process.launch()
  process.waitUntilExit()
  
  // `B`
  #!/usr/bin/swift 
  print("intpu something")
  let input = readLine()
  print("input: \(input)")
  </code></pre>
  
  <p>I did not set the <code>process</code>'s input since according to the doc:</p>
  
  <blockquote>
    <p>If this method isn’t used, the standard input is inherited from the process that created the receiver.</p>
  </blockquote>
  
  <hr>
  
  <p>UPDATE:</p>
  
  <p><code>A</code> is an executable package created using Swift Package Manager. I used <code>swift package generate-xcodeproj</code> to generate an Xcode project file. I confirmed that if I run the executable built using <code>swift build</code> or <code>xcodebuild</code> in a shell, the problem with getting input from stdin from <code>B</code> arose. However if I run it directly inside Xcode, by pressing <code>command + R</code> inside Xcode, then it worked. So if I understand the difference between running an executable in a shell and Xcode, I can probably make everything work.</p>