-
Notifications
You must be signed in to change notification settings - Fork 744
Allow exec to handle stdin inputs #432
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
Conversation
|
Is there a way to add tests for this? If not, that's fine. |
|
@MatthieuLemoine Seems like the |
|
@nfischer I will look into it. About the tests, I think that we can't simulate stdin input during execSync as it blocks the event loop. |
|
@nfischer It seems that on Windows the process wont quit sometimes even when ending process.stdin. I have run the tests on Windows using Node v4.4.3. |
|
I'll take a look later. Thanks! |
|
Just tried this out on node v6 Ubuntu 15.10. I noticed that it does accept input, but won't show my user input (which might make this non intuitive). I also noticed that @MatthieuLemoine Any idea on how we might be able to work around these issues? |
|
@nfischer As I said,
'use strict';
const childProcess = require('child_process');
const npm = childProcess.exec('npm init', (err, stdout, stderr) => {
console.log(err, stdout, stderr);
});
npm.stdout.pipe(process.stdout);
npm.stderr.pipe(process.stderr);
process.stdin.pipe(npm.stdin);I am able to see my input using Node 4 & Node 5. I will try using Node6 |
Ok good to know. I can try node v4 and 5 later today. I'd just like to get a solution that fixes the issue entirely, instead of just a partial fix. |
@nfischer With which command did you have this ? |
$ node
> require('shelljs/global')
{}
> exec('npm init')
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See `npm help json` for definitive documentation on these fields
and exactly what they do.
Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
name: (PR_432) version: (1.0.0) description: entry point: (index.js) test command: git repository: keywords: author: license: (ISC) About to write to /home/nate/PR_432/package.json:
{
"name": "lkjlkj",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"shelljs": "^0.7.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Is this ok? (yes) [1] 11300 terminated node
TerminatedIt gets terminated because I run node v6.0.0, Ubuntu 15.10, running from within |
|
Hello guys! I'd like to know how's going with this fix? Do you need some help? Analyzing this issue, we can see there's a misconception with the nodejs The Piping the processes using I understand What do you think about it? 😄 |
|
@dowglaz thanks for the follow-up. That info is very helpful! This is something I was working on addressing in #524. I think for backwards compatibility, we should just leave |
|
Wow, perfect! I didn't see this PR! |
Handling stdin inputs
Fix #424.
Well not really..
It will not work with
npm init. It seems thatnpm initimproperly returns after execution. Node's exec callback is never called.I tested it using Node v5.11.0 with the following script waiting for input :
Exec refactoring
After diving in node child_process, it seems that creating & executing a script file is the only solution.
Synchronous versions of spawn and exec only allow to get the full output if you didn't set the opts.stdio option. But then you can't have the live output. Wontfix (BTW : opened for shelljs)
Then I tried to create a custom stream to intercept the output but opts.stdio only accepts a small set of streams (see waiting for merge doc update) :
None of them can be used for our case.