New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use inherited stdin instead of piped #192
Conversation
child.on('exit', code => { | ||
child.on('close', () => { | ||
if (piped) process.stdin.unpipe(child.stdin) | ||
let output = new ProcessOutput({ | ||
code, stdout, stderr, combined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
combined
, message
props are not declaredProcessOutput
iface. The rest seems fine to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, message
goes to the parent class. And combined
is used inside toString() func.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I'm a little confused about the logic.
let child = spawn(prefix + cmd, { | ||
cwd, | ||
shell: typeof shell === 'string' ? shell : true, | ||
stdio: [promise._inheritStdin ? 'inherit' : 'pipe', 'pipe', 'pipe'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use 'inherit' instead of 'pipe' for this parameter.
in cases like this, errors are reported:
#!/usr/bin/env zx
const sleep = () => new Promise((resolve) => setTimeout(resolve, 1000));
let p = $`read var; echo "$var";`
await sleep();
p.stdin.write('Hello, stdin!\n') // p.stdin is null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stdin of the child process is not necessarily a synchronous call, so is there a flaw in the design?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is done to allow interactively work with subprocesses if nothing is "touched".
This way to can make it work:
#!/usr/bin/env zx
// sleep() already defined in zx
let p = $`read var; echo "$var";`
let stdin = p.stdin // force piped mode.
await sleep(1000);
stdin.write('Hello, stdin!\n')
See http://go/gh/google/zx/blob/main/examples/interactive.mjs
Well, probably we can create separate API for setting inherited stdin. Like
$`...`.inheritStdin()
Fixes #191
This PR refactors ProcessPromise.
Now call $ does not create the child process. then() creates child process.