[英]Automate Node.js CLI program from shell script
我并尝试执行 node.js CLI 程序,该程序接受用户的输入来决定下一步。
在此之后我想发送1
作为输入,我可以通过node index.js
启动程序。 有没有办法可以输入我的 node.js 程序。
我的愚蠢大脑想出了以下脚本
--Script.sh--
node index.js
1
2
这显然没有用。
也许这会起作用?
创建一个 answers.txt 文件,每个输入都在自己的行中:
first
second
然后像这样运行命令: node index.js < answers.txt
<
会将输入重定向到指定的文件而不是标准输入。
关于什么:
#!/bin/dash
echo "Type something or 'q' to quit and press Enter!"
while read user_input; do
if [ "$user_input" = 'q' ]; then
break
else
echo "You've typed: ""$user_input"
# do something
# node index.js "$user_input"
fi
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.