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

Prompts does not handle stdin redirection correctly #427

Open
venomdev opened this issue Feb 22, 2025 · 0 comments
Open

Prompts does not handle stdin redirection correctly #427

venomdev opened this issue Feb 22, 2025 · 0 comments

Comments

@venomdev
Copy link

venomdev commented Feb 22, 2025

Describe the bug

When running a script that uses prompts it can not accept a stdin redirection from a file. The file will be read but prompts ignores the new lines so that the whole file is used as the input to the first prompt only.

Steps to reproduce the behavior:

  1. Create a script that accepts multiple text inputs (prompts-test.js)
const prompts = require('prompts');

async function run() {
    const response = await prompts([
        {
            type: 'text',
            name: 'name',
            message: 'What is your project name?',
            initial: 'my-project',
        },
        {
            type: 'text',
            name: 'description',
            message: 'What is your project description?',
            initial: 'My project description',
        }
    ]);

    console.log('User entered:', response);
}

run().catch(e => {
    console.error(e);
    process.exit(1);
});
  1. Create a text file with answers to the prompt questions (project.txt)
My test project
A test project using prompts
  1. Run the script with redirection from the text file
node prompts-test.js < project.txt

Expected behavior

The script should accept each line from the text file as an answer to the single prompt and then show the response as an object on the console.

✔ What is your project name? … My test project
✔ What is your project description? … A test project using prompts
User entered: {
  name: 'My test project',
  description: 'A test project using prompts'
}

The actual result is that the script does not finish, does not show the console message, and does not trigger the catch exception function.

node prompts-test.js < project.txt
✔ What is your project name? … My test projectA test project using prompts


? What is your project description? › My project description%   

System

  • OS: Linux 6.8.0-53-generic x86_64
  • Terminal: zsh 5.9
  • Node version: v22.13.0

Additional context

The redirection to accept input from text files would be a great benefit to automate initializing projects using scripts and without waiting for user input.

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

1 participant