I try to convert a sample ruby script to an executable file with the ocra gem.Here is my ruby script.
puts "Hello word"
Gives me the following error when running ocra test.rb
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/ocra-1.3.11/bin/ocra:34:in `tr': invalid byte sequence in UTF-8 (ArgumentError)
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/ocra-1.3.11/bin/ocra:34:in `to_posix'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/ocra-1.3.11/bin/ocra:57:in `subpath?'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/ocra-1.3.11/bin/ocra:611:in `block (2 levels) in find_gem_files'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/ocra-1.3.11/bin/ocra:609:in `each'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/ocra-1.3.11/bin/ocra:609:in `block in find_gem_files'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/ocra-1.3.11/bin/ocra:597:in `each'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/ocra-1.3.11/bin/ocra:597:in `find_gem_files'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/ocra-1.3.11/bin/ocra:755:in `build_exe'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/ocra-1.3.11/bin/ocra:1231:in `block in <top (required)>'
My version of ruby
ruby -v
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x64-mingw-ucrt]
Is there a good way to convert a ruby script to an executable file ?
The issue was my Window username contained the character è. Like Casper mentioned, UFT-8 must be respected with ocra. I followed this link to solve my problem and then restarted ocra and the issue was fixed.
Change user name on windows 10
Related
As I stated in the Question title, I have installed Ruby 3.0 version in Windows 10 64Bit OS and I have coded this program for Password generation and copying the generated password to clipboard(PasswordGenerator.rb):
require 'clipboard'
CHARS = ('0'..'9').to_a + ('A'..'Z').to_a + ('a'..'z').to_a + ('!'..'?').to_a
def GeneratePassword(length=16)
return CHARS.sort_by{rand}.join[0...length.to_i]
end
Clipboard.copy (GeneratePassword 15)
And I have also installed all the necessary gems that could be needed as dependencies and even sub-dependencies with these:
gem install ocra
gem install --install-dir ./gems thor ftools nokogiri rubygems clipboard
But the second command above installed all the dependencies inside (dir of PasswordGenerator.rb)/gems/gems directory instead of (dir of PasswordGenerator.rb)/gems/ folder, but I ignored that as maybe gem install --install-dir sucked once due to glitch.
But now as I try to build standalone executable from PasswordGenerator.rb with ocra in the same directory it gives me this error. I want a permanent solution of this issue with understanding of why and how ocra wasn't able to add the gems even when specified in the build command the extra paths like ocra PasswordGenerator.rb ./gems/gems and threw this error:
path/to/ruby/gems/3.0.0/gems/ocra-1.3.11/bin/ocra:693:in `block (3 levels) in find_gem_files': undefined method `relative_path_from' for nil:NilClass (NoMethodError)
from path/to/ruby/gems/3.0.0/gems/ocra-1.3.11/bin/ocra:693:in `select'
from path/to/ruby/gems/3.0.0/gems/ocra-1.3.11/bin/ocra:693:in `block (2 levels) in find_gem_files'
from path/to/ruby/gems/3.0.0/gems/ocra-1.3.11/bin/ocra:685:in `each'
from path/to/ruby/gems/3.0.0/gems/ocra-1.3.11/bin/ocra:685:in `block in find_gem_files'
from path/to/ruby/gems/3.0.0/gems/ocra-1.3.11/bin/ocra:627:in `each'
from path/to/ruby/gems/3.0.0/gems/ocra-1.3.11/bin/ocra:627:in `find_gem_files'
from path/to/ruby/gems/3.0.0/gems/ocra-1.3.11/bin/ocra:755:in `build_exe'
from path/to/ruby/gems/3.0.0/gems/ocra-1.3.11/bin/ocra:1231:in `block in <top (required)>'
My executing environment:
windows 7 x64, Traditional Chinese Edition
rubyinstaller-1.9.3-p484
DevKit-tdm-32-4.5.2-20110712-1620-sfx
calabash-android 0.5.2
The command I use:
calabash-android run xxx.apk
The error message I get:
No test server found for this combination of app and calabash version. Recreating test server.
C:/Ruby193/lib/ruby/gems/1.9.1/gems/calabash-android-0.5.2/lib/calabash-android/helpers.rb:159:in `scan': invalid byte sequence in CP950 (ArgumentError)
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/calabash-android-0.5.2/lib/calabash-android/helpers.rb:159:in `extract_md5_fingerprint'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/calabash-android-0.5.2/lib/calabash-android/helpers.rb:151:in `block (2 levels) in fingerprint_from_apk'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/calabash-android-0.5.2/lib/calabash-android/helpers.rb:137:in `chdir'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/calabash-android-0.5.2/lib/calabash-android/helpers.rb:137:in `block in fingerprint_from_apk'
from C:/Ruby193/lib/ruby/1.9.1/tmpdir.rb:83:in `mktmpdir'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/calabash-android-0.5.2/lib/calabash-android/helpers.rb:136:in `fingerprint_from_apk'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/calabash-android-0.5.2/bin/calabash-android-build.rb:2:in `calabash_build'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/calabash-android-0.5.2/lib/calabash-android/helpers.rb:92:in `build_test_server_if_needed'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/calabash-android-0.5.2/bin/calabash-android-run.rb:16:in `calabash_run'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/calabash-android-0.5.2/bin/calabash-android:85:in `<top (required)>'
from C:/Ruby193/bin/calabash-android:24:in `load'
from C:/Ruby193/bin/calabash-android:24:in `<main>'
It's because while running Ruby on windows Chinese edition, the default encoding is UTF-8.
we have to force Ruby to run it using UTF-8 encoding. So I modify the command as below:
[Ruby installed path] -EUTF-8 [calabash-andorid installed path] run [apk path]
p.s. My calabash-android installed path:
C:\Ruby193\lib\ruby\gems\1.9.1\gems\calabash-android-0.5.2\bin\calabash-android
The third line in my ruby script
# encoding: utf-8
require "mail"
results in the following error
/usr/local/share/gems1.9/gems/json-1.8.1/lib/json/pure/parser.rb:242:in `rescue in parse_string': Caught Encoding::CompatibilityError at '[{"content-type":"ap': incompatible encoding regexp match (ASCII-8BIT regexp with UTF-8 string) (JSON::ParserError)
from /usr/local/share/gems1.9/gems/json-1.8.1/lib/json/pure/parser.rb:213:in `parse_string'
from /usr/local/share/gems1.9/gems/json-1.8.1/lib/json/pure/parser.rb:257:in `parse_value'
from /usr/local/share/gems1.9/gems/json-1.8.1/lib/json/pure/parser.rb:121:in `parse'
from /usr/local/share/gems1.9/gems/json-1.8.1/lib/json/common.rb:155:in `parse'
from /usr/local/share/gems1.9/gems/json-1.8.1/lib/json/common.rb:334:in `load'
from /usr/local/share/gems1.9/gems/mime-types-2.3/lib/mime/types/loader.rb:210:in `load_from_json'
from /usr/local/share/gems1.9/gems/mime-types-2.3/lib/mime/types/loader.rb:61:in `block in load_json'
from /usr/local/share/gems1.9/gems/mime-types-2.3/lib/mime/types/loader.rb:60:in `each'
from /usr/local/share/gems1.9/gems/mime-types-2.3/lib/mime/types/loader.rb:60:in `load_json'
from /usr/local/share/gems1.9/gems/mime-types-2.3/lib/mime/types/loader.rb:87:in `load'
from /usr/local/share/gems1.9/gems/mime-types-2.3/lib/mime/types.rb:280:in `load_default_mime_types'
from /usr/local/share/gems1.9/gems/mime-types-2.3/lib/mime/types.rb:307:in `<class:Types>'
from /usr/local/share/gems1.9/gems/mime-types-2.3/lib/mime/types.rb:62:in `<top (required)>'
from /usr/local/share/ruby19/site_ruby/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/share/ruby19/site_ruby/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/share/gems1.9/gems/mail-2.6.1/lib/mail.rb:9:in `<module:Mail>'
from /usr/local/share/gems1.9/gems/mail-2.6.1/lib/mail.rb:2:in `<top (required)>'
from /usr/local/share/ruby19/site_ruby/rubygems/core_ext/kernel_require.rb:135:in `require'
from /usr/local/share/ruby19/site_ruby/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
from /usr/local/share/ruby19/site_ruby/rubygems/core_ext/kernel_require.rb:144:in `require'
from Mailer.rb:3:in `<main>'
note this error only occurs in production on AWS with Ruby 1.9.3. In development with Ruby 2, it works fine.
Sorry, this is no solution, only an explanation why it works correct with ruby 2.0 but not with 1.9.3:
Since ruby 2.0 all scripts are utf-8-encoded (unless something else is defined)
What is Ruby 2.0.0
[...]
Language core features
[...]
The UTF-8 default encoding, which make many magic comments omissible
Source: https://www.ruby-lang.org/en/news/2013/02/24/ruby-2-0-0-p0-is-released/
In Ruby 1.9 UTF-8 is not the default, so there may be a encoding difference between your script in UTF-8 and the script you call.
I solved this issue adding this to my gemfile:
gem 'oj'
gem 'oj_mimic_json'
then run bundle install and try to run server again
Trying to compile a ruby script to a Windows executable using ocra. For some reason since adding business_time to the script, it refuses to compile. If I remove the require 'business_time' it will compile. So I created a script for just business_time and it works but will not compile. Struggling to see what the issue is from the ERROR message.
Thanks in advance.
require 'rubygems'
require 'business_time'
puts 1.business_day.ago.strftime("%Y%m%d")
puts 1.business_day.ago.strftime("%m/%d/%Y")
C:/Ruby/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:467: Use
RbConfig instead o
f obsolete and deprecated Config.
C:/Ruby/lib/ruby/gems/1.9.1/gems/i18n-0.6.1/lib/i18n/tests/basics.rb:8:in
test'
: unknown command 'a' (ArgumentError)
from C:/Ruby/lib/ruby/gems/1.9.1/gems/i18n-0.6.1/lib/i18n/tests/basics.r
b:8:in'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/i18n-0.6.1/lib/i18n/tests/basics.r
b:3:in <module:Tests>'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/i18n-0.6.1/lib/i18n/tests/basics.r
b:2:in'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/i18n-0.6.1/lib/i18n/tests/basics.r
b:1:in <top (required)>'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:467:inconst_
get'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:467:in block
(3 levels) in attempt_load_autoload'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:464:ineach'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:464:in block
(2 levels) in attempt_load_autoload'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:462:ineach'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:462:in block
in attempt_load_autoload'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:456:inloop'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:456:in attemp
t_load_autoload'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:679:inbuild_
exe'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:1138:in `block
in '
C:\Ruby>
I had Compass 0.12 (a ruby gem) installed on Ubuntu Oneiric with no problems I have updated to Precise formatting / and keeping /home, so I needed to reinstall ruby (1.9.3).
I get this error now when I compile a SCSS file:
compass watch --trace
Change detected at 12:45:09 to: style.scss overwrite css/style.css
Dear developers making use of FSSM in your projects, FSSM is essentially dead at this point. Further development will be taking place in the new shared guard/listen project. Please let us know if you need help transitioning! ^_^b - Travis Tilley
>>> Compass is polling for changes. Press Ctrl-C to Stop.
ArgumentError on line ["46"] of /usr/lib/ruby/1.9.1/pathname.rb: invalid byte sequence in US-ASCII
/usr/lib/ruby/1.9.1/pathname.rb:46:in `chop_basename'
/usr/lib/ruby/1.9.1/pathname.rb:102:in `cleanpath_aggressive'
/usr/lib/ruby/1.9.1/pathname.rb:90:in `cleanpath'
/usr/lib/ruby/1.9.1/pathname.rb:452:in `relative_path_from'
/var/lib/gems/1.9.1/gems/fssm-0.2.9/lib/fssm/path.rb:82:in `split_path'
/var/lib/gems/1.9.1/gems/fssm-0.2.9/lib/fssm/path.rb:70:in `run_callback'
/var/lib/gems/1.9.1/gems/fssm-0.2.9/lib/fssm/path.rb:56:in `callback_action'
/var/lib/gems/1.9.1/gems/fssm-0.2.9/lib/fssm/path.rb:36:in `update'
/var/lib/gems/1.9.1/gems/fssm-0.2.9/lib/fssm/state/directory.rb:39:in `block in modified'
/var/lib/gems/1.9.1/gems/fssm-0.2.9/lib/fssm/state/directory.rb:37:in `each'
/var/lib/gems/1.9.1/gems/fssm-0.2.9/lib/fssm/state/directory.rb:37:in `modified'
/var/lib/gems/1.9.1/gems/fssm-0.2.9/lib/fssm/state/directory.rb:18:in `refresh'
/var/lib/gems/1.9.1/gems/fssm-0.2.9/lib/fssm/backends/polling.rb:17:in `block (2 levels) in run'
/var/lib/gems/1.9.1/gems/fssm-0.2.9/lib/fssm/backends/polling.rb:17:in `each'
/var/lib/gems/1.9.1/gems/fssm-0.2.9/lib/fssm/backends/polling.rb:17:in `block in run'
/var/lib/gems/1.9.1/gems/fssm-0.2.9/lib/fssm/backends/polling.rb:15:in `loop'
/var/lib/gems/1.9.1/gems/fssm-0.2.9/lib/fssm/backends/polling.rb:15:in `run'
/var/lib/gems/1.9.1/gems/fssm-0.2.9/lib/fssm/monitor.rb:26:in `run'
/var/lib/gems/1.9.1/gems/fssm-0.2.9/lib/fssm.rb:70:in `monitor'
/var/lib/gems/1.9.1/gems/compass-0.12.1/lib/compass/commands/watch_project.rb:89:in `perform'
/var/lib/gems/1.9.1/gems/compass-0.12.1/lib/compass/commands/base.rb:18:in `execute'
/var/lib/gems/1.9.1/gems/compass-0.12.1/lib/compass/commands/project_base.rb:19:in `execute'
/var/lib/gems/1.9.1/gems/compass-0.12.1/lib/compass/exec/sub_command_ui.rb:43:in `perform!'
/var/lib/gems/1.9.1/gems/compass-0.12.1/lib/compass/exec/sub_command_ui.rb:15:in `run!'
/var/lib/gems/1.9.1/gems/compass-0.12.1/bin/compass:29:in `block in <top (required)>'
/var/lib/gems/1.9.1/gems/compass-0.12.1/bin/compass:43:in `call'
/var/lib/gems/1.9.1/gems/compass-0.12.1/bin/compass:43:in `<top (required)>'
/usr/local/bin/compass:19:in `load'
/usr/local/bin/compass:19:in `<main>'
(The "Dear developers" message is part of the output).
This error doesn't appear the first time I make a change to the scss file, but the second.
In addition, compass "eats" one "s" in some files and, instead of compiling them as "style.css" (what it should be from the file's name) it does as "tyle.css".
I've spend 3 hours looking at similar problems here but I couldn't solve it. I tried including # encoding: utf-8 on the top of some files with no luck.
Please explain step by step what should I do, since I am a total noob with Ruby (I just use it because of SASS).
I think there is some problem with the pathname, maybe it contains an invalid non-ASCII sequence; probably the eaten "s" is the problem, maybe it is an invalid character, or maybe a character near to it; try to ensure path is ASCII.
Or maybe a bug in precise readline package? Try to install ruby 1.9.3 via RVM, RVM should use readline bundled with it (see the comments below for details)
From what I can see, the file in question pathname.rb contains this function that seems to be where the trouble is:
def chop_basename(path)
base = File.basename(path)
if /\A#{SEPARATOR_PAT}?\z/o =~ base
return nil
else
return path[0, path.rindex(base)], base
end
end
private :chop_basename
Here's a link to a similar question with the same issue:
Ruby on Rails application won’t start using Passenger when there are non-ASCII characters in the app path
So the fix is clearly to stick with us-ascii pathnames.
Here's a snippet from the doc on that class:
Pathname represents a pathname which locates a file in a filesystem. The pathname depends on OS: Unix, Windows, etc. Pathname library works with pathnames of local OS. However non-Unix pathnames are supported experimentally.
As to why it worked before and doesn't now, that's hard to say. It's possible that some other library on your system changed, or that the upgrade to ruby 1.9.3 caused a minor change that introduced the error.