Is it possible to write a shell command that conne

2019-09-18 05:03发布

Is it possible to script the following on OSX?

heroku run console
load 'init.rb'

The following does not work:

alias 'heroku_init=heroku run console; load "init.rb"'

It seems that the shell has to wait for the Heroku console to connect, or needs a way to send the load command to the Heroku console instead of the bash shell.

2条回答
The star\"
2楼-- · 2019-09-18 05:09

Big ups to camilo-santana for the answer:

#!/usr/bin/expect -f
set timeout -1
spawn heroku console
expect "irb(main):001:0>"
send "load 'app/init.rb'\r"
interact

It can also be done with an alias:

alias 'hc=heroku run console -- -r ./app/init.rb'
查看更多
男人必须洒脱
3楼-- · 2019-09-18 05:12

What you want it to send load 'init.rb' to the standard input of the heroku run console program. You do that in the shell using the pipe operator:

echo "load 'init.rb'" | heroku run console

This works but notice it makes the console hang, if you want to input some more commands manually you can do:

{ echo "load 'init.rb'"; cat } | heroku run console

Hope this helps ;)

查看更多
登录 后发表回答