Skip to content

Builtin standard inputs/outputs to share the current process' descriptors #145

@cmcgee1024

Description

@cmcgee1024

When using subprocess in the context of scripting it's very common to share the current process standard output, standard error, and sometimes even standard input. this is often what happens when running in a shell, and it allows interactive tools like vim to be run in this context if that's the goal the script.

It's possible to do this today with something like the following in a collected result invocation:

try await run(..., output: .fileDescriptor(FileDescriptor.standardInput, closeAfterSpawningProcess: false))

A similar pattern can be applied for standard error, and standard input.

This isn't very discoverable, it's verbose, and it's important that the file descriptor not be closed after spawning in most cases like this.

Describe the solution you'd like
Instead of this, there should be much simpler helper functions on the Input/Output protocols to hook into the standard input/output/error.

try await run(..., input: .standardInput, output: .standardOutput, error: .standardError)

This is shorter, clearer, and the file descriptors are left open until the calling process finishes instead of being accidentally closed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions