admin管理员组文章数量:1405750
I am creating a server application and I would like to be able to write mands like start server
, stop server
, broadcast("clients","Hello")
in to my application but I can't figure out how to do it in node.
I do know how it would look inside python.
while on == 1:
cmd = raw_input("user> ")
if cmd == "start server":
startserver()
elif cmd == "stop server":
stopserver()
on = 0
I have seen some npm modules for this but they require me to write arguments, I want to make this a console type application.
Thanks
I am creating a server application and I would like to be able to write mands like start server
, stop server
, broadcast("clients","Hello")
in to my application but I can't figure out how to do it in node.
I do know how it would look inside python.
while on == 1:
cmd = raw_input("user> ")
if cmd == "start server":
startserver()
elif cmd == "stop server":
stopserver()
on = 0
I have seen some npm modules for this but they require me to write arguments, I want to make this a console type application.
Thanks
Share asked Aug 16, 2013 at 6:08 C1DC1D 3,2442 gold badges23 silver badges21 bronze badges 1- Thanks for referencing python. Only for that reason I stumbled upon this answer! – jneuendorf Commented Jan 21, 2020 at 19:08
2 Answers
Reset to default 5Here's a snippet that was recently removed from mander.js. Something along these lines should work.
process.stdout.write("user> ");
process.stdin.setEncoding('utf8');
process.stdin.once('data', function(val){
//look at val here and execute startserver() et al accordingly
}).resume();
This page explains exactly what you need
本文标签: javascriptrawinput alternative for nodejsStack Overflow
版权声明:本文标题:javascript - raw_input alternative for node.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744917248a2632070.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论