swift-foundation icon indicating copy to clipboard operation
swift-foundation copied to clipboard

Process / NSTask

Open iCharlesHu opened this issue 2 years ago • 3 comments
trafficstars

We need to reimagine what Process should look like in Swift. Most likely we will introduce a new type.

rdar://118127512

iCharlesHu avatar Nov 08 '23 18:11 iCharlesHu

FWIW, I did some work on launching a Process in Swift. It’s probably not what I’d want in Foundation as-is, but it can give some ideas.

https://github.com/xcode-actions/XcodeTools/blob/main/Sources/XcodeTools/Process/ProcessInvocation.swift

On the top of my head, my main pain points were (unordered):

  • No possibilities of sending file descriptors to the child;
  • No easy streaming of process output (bonus, w/ fd differentiation);
  • PGID is different on child process (and there is no option to change that);
  • Process does not search for the executable in PATH for non-absolute paths.

There are other problems with the current API of course, but they are more obvious.

Frizlab avatar Nov 08 '23 20:11 Frizlab

I think that one thing that I would like to bring up while this is early in the process - Windows likes to throw a stupid wrench into this :(. The environment control block should be case insensitive. This is particularly important for Path (vs PATH) and any possible case variant which should be treated equivalently.

compnerd avatar Nov 25 '23 23:11 compnerd

Pitch is up: https://github.com/apple/swift-foundation/pull/397

iCharlesHu avatar Feb 02 '24 22:02 iCharlesHu