denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
94.02k stars 5.23k forks source link

🐛Unable to connect sub-process standard input/output to a terminal with `Deno.Command` #23587

Open rivy opened 4 months ago

rivy commented 4 months ago

Version: Deno 1.40.0

With Deno.run(), the subprocess could be connected to a terminal (or any file) with this code...

const isWinOS = Deno.build.os === 'windows';
const devTTY = Deno.openSync(isWinOS ? 'CONIN$' : '/dev/tty');
const process = Deno.run({
    cmd: ['stty', 'size'],
    stdin: devTTY.rid,
    stderr: 'piped',
    stdout: 'piped',
});
//...

With the deprecation of Deno.run() and rids (replaced with Deno.Command), this doesn't seem possible anymore.

NodeJS allows more flexibility, allowing the use of Stream objects and connection of extra streams beyond the basic three (STDIN, STDERR, and STDOUT), opaquely using their underlying file descriptors.

Could Deno.Command have more flexibility to use FsFiles in a similar manner (while keeping rids internal and opaque)?

lucacasonato commented 3 months ago

I propose that we allow ReadableStream as stdin, but only if that ReadableStream comes from FsFile#readable, Deno.stdin.readable, Deno.Conn#readable, or Deno.ChildProcess#stdout, or Deno.ChildProcess#stderr. We initially error for any user created ReadableStream objects.

We can then add support for custom ReadableStream objects down the road.

bartlomieju commented 2 weeks ago

Discussed with Luca and we want to enable passing FsFile as well as ReadableStream and WriteableStream to the API. That said, it's a feature that is additive and we don't consider that it's a 2.0 release blocker.