2

Im trying to run a bash script through node.js with child_process

the part that is not working in my bash script when I am running the line

(echo "PASSWORD"; echo "PASSWORD"; echo "NAME"; echo "ORGANIZATION"; echo "ORGANIZATION"; echo "CIUDAD"; echo "REGION"; echo "PAIS"; echo "yes";echo) |keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000

Basically, I'm trying to answer different options when I'm running the keytool but its not working (the process is stuck waiting for an option)

In node I am running

 exec('./script.sh', {
  cwd: '/Users/MY/Directory'
}, (error, stdout, stderr) => {
      if (error) {
          console.error(`exec error: ${error}`);
          return;
      }
      console.log(`stdout: ${stdout}`);
      console.log(`stderr: ${stderr}`);
  }).stderr.pipe(process.stderr);

Is there a solution for this?

Thanks

1 Answer 1

1

This wont work as each echo happens and only the last echo is even piped to your program.

The way I would handle this is probably with expect.

See https://linux.die.net/man/1/expect

Also you can use the -dname flag to set these fields. Which is way cleaner than dealing with the interactive prompts.

"cn=Mark Jones, ou=Java, o=Oracle, c=US"

Sign up to request clarification or add additional context in comments.

1 Comment

would you mind elaborating a bit more on how to use the -dname flag?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.