Problem:
In Ruby, Open3.popen3 is a good way to execute a system command and get the output of the command. Following is the a piece of code that does this.
Open3.popen3(*cmd) do |stdin, stdout, stderr, wait_thread|
err = stderr.gets
out = stdout.gets
[stdin, stdout, stderr].each{|stream| stream.send('close')}
exit_status = wait_thread.value
end
It works well when your command throws some error to stderr. However, it got stuck forever if your command executes successfully without any error message, BECAUSE err=stderr.gets GOT STUCK.
Solution:
READ stdout FRIST
Wednesday, December 12, 2012
Monday, December 10, 2012
[SOLVED]Trouble-Shooting on Ruby on Rails Installation
1. Install ruby1.9.1 on Ubuntu
Dependent on your OS version, you will have a default ruby version, which is usually outdated.
Solution:
sudo apt-get install ruby1.9.1
sudo update-alternatives --config ruby
Select the number which corresponds to your newly installed ruby1.9.1 and enter
ruby -v, to see your current ruby version
2. Update rubygems
On Debian Linux, "sudo gem update --system" is not allowed.
Solution:
sudo gem install rubygems-update
sudo update_rubygems
sudo update-alternatives --config gem
Select the number which corresponds to your newly updated gem and enter
gem -v, to see your current gem version
3. Missing sqlite3, coffee-rails or some other gems
Solution:
bundle install
4. rake db:create - Could not find a JavaScript runtime
Solution:
sudo apt-get install nodejs
Alternative solution(not work on Ubuntu 11.10):
Add following lines to Gemfile in your newly created app directory
"gem 'therubyracer'"
"gem ' libv8'"
Run "bundle install"
5. Installation of mysql2
Solution:
sudo apt-get install libmysqlclient-dev
sudo gem install mysql2 -v '0.3.11'
Add following line to Gemfile
"gem 'mysql2'"
Dependent on your OS version, you will have a default ruby version, which is usually outdated.
Solution:
sudo apt-get install ruby1.9.1
sudo update-alternatives --config ruby
Select the number which corresponds to your newly installed ruby1.9.1 and enter
ruby -v, to see your current ruby version
2. Update rubygems
On Debian Linux, "sudo gem update --system" is not allowed.
Solution:
sudo gem install rubygems-update
sudo update_rubygems
sudo update-alternatives --config gem
Select the number which corresponds to your newly updated gem and enter
gem -v, to see your current gem version
3. Missing sqlite3, coffee-rails or some other gems
Solution:
bundle install
4. rake db:create - Could not find a JavaScript runtime
Solution:
sudo apt-get install nodejs
Alternative solution(not work on Ubuntu 11.10):
Add following lines to Gemfile in your newly created app directory
"gem 'therubyracer'"
"gem ' libv8'"
Run "bundle install"
5. Installation of mysql2
Solution:
sudo apt-get install libmysqlclient-dev
sudo gem install mysql2 -v '0.3.11'
Add following line to Gemfile
"gem 'mysql2'"
Subscribe to:
Posts (Atom)