Skip to content

Provide a way to supply stdin to Process.runSync #34255

Open
@gspencergoog

Description

Right now, the only way to supply stdin to a process is to use the static Process.start(), and then add to the returned Process's stdin stream.

This is nice when you want to stream large amount of data without blocking, but if all you want to do is supply a little input to a process, it's overkill, especially because of the viral nature of async/await. If I want to add a simple process call that takes some stdin deep in some API, it means that the entire call chain to that API needs to all of a sudden change to be async, which is not always feasible.

Ideally, I'd like to see something like this:

class Process {
  //...
  ProcessResult runSync (
    String executable,
    List<String> arguments, {
    String workingDirectory,
    Map<String, String> environment,
    bool includeParentEnvironment: true,
    bool runInShell: false,
    Encoding stdoutEncoding: systemEncoding,
    Encoding stderrEncoding: systemEncoding,

    // New API:
    Encoding stdinEncoding: systemEncoding,
    Iterable<int> stdin,
  })
  // ...
}

Where the entire contents of the stdin Iterable is supplied to the called process when invoked.
[It may or may not need to have an encoding specified, but I think it probably should have one, and transform it before sending it down to the process.]

Imagine needing to supply a "y" to a command that waits for user confirmation: do you really want to rewrite your entire API as async because of that one "y"? :-)

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestlibrary-iotriagedIssue has been triaged by sub teamtype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions