问题
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
orecho 'exampleuser\r\nexamplepassword\r\nex@email.com'| npm adduser
orecho '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