1

I am having trouble getting bash to relinquish control of the pipe to stdin. I want to pass in the username and password to a program and then have that same program read from stdin rather than the pipe! This is what I have tried:

alias pandora='echo -e "$(cat ~/.musik/name)\n$(cat ~/.musik/pass | base64 --decode)" | pianobar' 

That's in my .bashrc. First, it cat's the username/password files and then pipes that into pianobar (pandora in the terminal). The username and password get in there, however, pianobar is expecting more input. Pianobar is asking for a number (to be able to play, for example, station 12), but when I type and hit enter, nothing happens because for some reason, it isn't expecting it to come from there.

How do I get the pipe to "relinquish" control?

Note: I have also tried

echo "$(cat ~/.musik/name) $(cat ~/.musik/pass | base64 --decode) " >>> pianobar 
0

2 Answers 2

1

There are 2 options you can try:

Easy way: (may not work for all sorts of commands (like pianobar in this case)

alias pandora='{ echo -e "$(cat ~/.musik/name)\n$(cat ~/.musik/pass | base64 --decode)"; cat; } | pianobar' 

Or with a bit cleanup & removal of UUOC:

alias pandora='{ cat ~/.musik/name; base64 --decode < ~/.musik/pass; cat; } | pianobar' 

Better way: use expect script. I could have written the script, but I don't know the login prompt that your application gives.

Sign up to request clarification or add additional context in comments.

11 Comments

I'd go with { cat; echo; cat | base64; cat; } | pianobar instead of this to avoid the unnecessary echo -e, etc.
^^ Agreed. I also have same opinion. I just preferred making minimal changes to OP's script. But edited giving that solution too.
Using an expect script is actually more certain to work the same way real TTY input does -- if the program varies its behavior on the return value of isatty(stdin), the cat hack may not work.
^^ Right. But isatty(stdin) is usually used for login stage. If Op's existing code is allowing login using redirected stdin, then quite likely (not certain), next cat would work too...
Ah, so I literally need it to relinquish control because it may need to read more than just one input. There are two problems: (1) you have to press enter (and pianobar reads key input like raw mode or something); (2) there is more than one input... so I could do while : ; do cat; done I guess.. any thoughts?
|
0

This is the proper way to configure pianobar auto login:

 mkdir ~/.config/pianobar/ && cd ~/.config/pianobar/ && touch config 

Run ^^^ in your command line then put the following in your new config file

 # User user = (Your Pandora email) password = (Your Pandora password) 

https://github.com/PromyLOPh/pianobar/blob/e945578ab22912049f1e547ce7b25b01089f7590/contrib/config-example

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.