Skip to content
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

child_process.execSync does not get input after using inquirer #792

Closed
Neunerlei opened this issue Mar 12, 2019 · 3 comments
Closed

child_process.execSync does not get input after using inquirer #792

Neunerlei opened this issue Mar 12, 2019 · 3 comments

Comments

@Neunerlei
Copy link

We use inquirer for a while now, but lately I got reports of an issue when we use inquirer in combination with childProcess.execSync(command, {stdio: 'inherit'});

The problem occurs if the child process is called after inquirer prompted something in the console.
(Currently I only found an issue when "type:list" was used)

As an example:

		const childProcess = require("child_process");
		const inquirer = require("inquirer");
		return inquirer.prompt([
			{
				name: "projectNameInputType",
				type: "list",
				message: "How do you want to specify the app/project name?",
				default: "wizard",
				choices: [
					{
						name: "Use the wizard",
						value: "wizard"
					},
					{
						name: "Input the name as a string",
						value: "manual"
					},
				]
			},
		]).then(answers => {
			// In our case this will ask the user for the ssh key's passphrase, but the input (you can still enter) will not reach the process. 
			const command = "git clone git@bitbucket.org:user/myrepo.git \"W:\\work\\labor\\tmp\\app\"";
			childProcess.execSync(command, {stdio: 'inherit'});
			return true;
		});

The error occurs with other processes like this as well.
childProcess.execSync("aws configure", {"stdio": "inherit"});

Strangely enough the second input (aws configure expects multiple inputs) works as expected...

After looking around a bit I found: #767 which lead me to the following workaround. If I put this code, right in front of my childProcess.execSync... everything works again as expected.

const readline = require("readline");
const rl = readline.createInterface({
	input: process.stdin,
	output: process.stdout
});
rl.close();

Node Version v11.11.0
Windows 10 Pro

@SBoudrias
Copy link
Owner

This looks like a Node.js bug; can you try reporting it over there?

@Neunerlei
Copy link
Author

As I did not read the code to determine what went wrong, but only tried what by #767 seemed logical; I don't see exactly what I should write them /o\

@joshuapinter
Copy link

joshuapinter commented May 25, 2020

FYI, I'm seeing something similar on macOS 10.15.4. I'm glad you posted this here so I don't think I'm going insane.

In my case, trying to get the result of an execSync that is interrupted no longer works after I use a non-List Inquirer.prompt.

For example,

Does not return result.

const questions = [ 
  {
    type:    "confirm",
    name:    "runAllTests",
    message: "Run All Tests?",
    default: true
  }
];

await Inquirer.prompt( questions );

const result = spawnSync( "env", [ "jest" ], { stdio: "inherit" } );

console.log( result ); // Does not get to this point when spawnSync is interrupted with Ctrl+C.

Does return result.

const questions = [ 
  {
    type:    "list",
    name:    "runAllTests",
    message: "Run All Tests?",
    choices: [ 
      { value: true, name: "Yes" },
      { value: false, name: "No" }
    ]
  },
];

await Inquirer.prompt( questions );

const result = spawnSync( "env", [ "jest" ], { stdio: "inherit" } );

console.log( result ); // Outputs result correctly when spawnSync is interrupted with Ctrl+C.

I'll use a List for now to ensure the result is shown but any ideas would be appreciated. I may also post a separate Issue here if that makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants