Windows cmd - Interact with user input prompt [npm] using oneliner

蓝咒 提交于 2020-01-04 06:34:26

问题


I am trying to pass in an input as one line to an user-input prompt, but am having difficulty working out how to do it correctly.

Specifically I am trying to login to npm using npm adduser (npm login is its alias)

When it's a singular value it works but this only gets me so far: echo exampleuser| npm adduser Username: exampleuser Password: Password: npm ERR! cb() never called!

But unfortunately when I try to add multiple commands together it goes awry. Eg:
echo 'exampleuser examplepassword ex@email.com'| npm adduser or
echo 'exampleuser\r\nexamplepassword\r\nex@email.com'| npm adduser or
echo 'exampleuser&& echo examplepassword&& echo ex@email.com'| npm adduser, etc...

Gets back errors along the lines of Username: 'exampleuser examplepassword' npm WARN Name must be lowercase Username: Username: npm ERR! cb() never called!

Any suggestions would be greatly appreciated.


回答1:


to pass several values, you have to pass several lines. echo isn't able to echo a line break, so you have to use several echo's

(
echo exampleUser
echo hisPassword
echo ex@email.com
)|npm adduser

As a single line:

(echo exampleUser&echo hisPassword&echo ex@email.com)|npm adduser

(note: NO space before &!)

(Note: this is how to pass several parameters; Can't test, if npm will actually accept them)



来源:https://stackoverflow.com/questions/43108767/windows-cmd-interact-with-user-input-prompt-npm-using-oneliner

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!