Nicolas Meienberger
Nicolas Meienberger

Reputation: 777

Node.js execute shell command which requires an input after a few seconds

I'm trying to use the now cli to purchase a domain through my Node.js server but I cannot figure out how to execute a shell command in Node and to automatically insert the input when asked.

Here's my command using child_process.exec

const { stdout } = await exec(`now --token ${NOW_TOKEN} domains buy ${domainName}.${tld}`)

This does nothing because the command is waiting input (y/N) to confirm buying the domain. They don't have any option in the commande to bypass the question like --yes.

How can I pass a string y + Enter when the process is waiting ?

Upvotes: 0

Views: 1226

Answers (1)

paulogdm
paulogdm

Reputation: 1801

Be careful. Your usage can certainly violate their ToS if you are reselling parts of their offering. You may need to reach out to their support channel for clarification.

Regarding the code. You can take a look at this file for inspiration: https://github.com/zeit/now/blob/master/packages/now-cli/test/integration.js

One alternative is:

stdin.write('y\n')

Upvotes: 1

Related Questions