Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9024487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:01:25+00:00 2026-06-16T06:01:25+00:00

My bash script looks like: read -p Do you wish to continue? yn #

  • 0

My bash script looks like:

read -p "Do you wish to continue?" yn
# further actions ...

And I just want to interact with this script using nodejs / child_process.
How can I detect that it’s waiting for the user input?

var spawn = require('child_process').spawn;
var proc = spawn('./script.sh');
proc.stdout.on("data", function(data) {
  console.log("Data from bash");
}
proc.stdin.on("data", function(data) {
  console.log("Data from bash"); // doesn't work :/
}

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T06:01:27+00:00Added an answer on June 16, 2026 at 6:01 am

    From the bash man page:

    read -p prompt
    

    Display prompt on standard error, without a trailing newline, before
    attempting to read any input. The prompt is displayed only if input is
    coming from a terminal
    .

    And I don’t think there a any way in node.js to detect that the script is waiting for input. The problems is actually that bash detects a non-terminal and disables the output to standard error. And even then you would have to read from stderr and not stdin to detect any waiting states.

    In the end, as Antoine pointed out, you might have to use tools like empty or Expect to wrap your shell-scripts and trick Bash to think it is in a terminal.

    Btw.: proc.stdin.write("yes\n") works fine. Thus you could work with the script, but won’t get any prompts on proc.stderr and will not know when the script actually reads the input. You can also immediately proc.stdin.write the input even if the script is not yet at the read -p statement. The input is buffered until the scripts eats it up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bash script that looks like this: #!/bin/sh previousRelease=`git describe --tags --match
I have a script that looks like this #!/bin/bash function something() { echo hello
I am writing a bash script that modifies a file that looks like this:
I'have a bash script calling a jar file like this: awk -f fileformat.awk list.txt
I have a bash script file which starts with a function definition, like this:
I have a simple test bash script which looks like that: #!/bin/bash cmd=rsync -rv
I have a bash script that looks like the following: #!/bin/bash FILES=public_html/*.php # */
My bash-script looks as following: echo "Description:" while [ $finishInput -eq 0 ]; do
I am trying to write a bash script that looks at two files with
Linux bash script: function Print() { echo $1 } Print OK This script runs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.