Rubygame on OS X shebang problem - ruby

I'm playing around with Rubygame. I installed it with the Mac Pack, and now I have the rsdl executable. rsdl game.rb works fine, but when I chmod +x the rb file, add the shebang to rsdl (tried direct path and /usr/bin/env rsdl) and try to execute it (./game.rb), it starts to flicker between the Terminal and rsdl which is trying to open, and eventually gives up and gives a bus error. Anyone know what's causing that? I'm on Snow Leopard (10.6.2) if it makes a difference.
Thanks.

I believe that this is a problem with embedded ruby. Ruby has a horrible hack to handle shebang execution which essentially it looks for "ruby" in the executable name (i.e. argv[0]). If your embedded ruby executable doesn't have "ruby" in its name, this hack fails, and you get an infinite loop (this occurs even with the stock ruby if you rename it). Assuming this is the case here, you can sym-link or mv rsdl to rsdl-ruby (or similar), change your shebang to #!/usr/bin/env rsdl-ruby and it will work.

There may be problems with where rsdl expects you to be executing from (i.e. from the executable, rather than a game file). The way i would find out is popping open the rsdl executable (presuming that it's just a ruby script), and poking around inside. I think it'd be useful also to know why you're trying to execute standalone from your ruby script.

Related

I can't run my Ruby program and I see errors in the terminal. I can't find the program

Good afternoon! I have a problem with Ruby. I downloaded this program from the official site https://www.ruby-lang.org/en/downloads/ on Fedora without any problems (using the command via the terminal). However, I cannot use the 'irb' command in the terminal to run Ruby on Linux as described here https://www.ruby-lang.org/en/documentation/quickstart/. Therefore, I cannot learn the Ruby programming language.Command 'irb' not found
I tried my best to run Ruby in other ways. One of them, as is customary in Fedora, is to write the name of the program in the terminal. But it opens a folder in which, I assume, Ruby is located (I can't find the folder itself either in Files or via the 'cd' command in the terminal). I kind of can open this folder in the terminal, but I can't find it in Files.
Oh, by the way, the 'irb' command doesn't work there. Only some real command for a program like this one will work: irb(main):001:0> "Hello World" (from https://www.ruby-lang.org/en/documentation/quickstart/). The program is and is not at the same time
Move on. I made a text document, wrote irb(main):001:0> "Hello World" in it (as written in "Ruby in Twenty Minutes"), and saved the file as hello.rb . Opened the hello.rb file path through the terminal and wrote 'ruby hello.rb' (without quotes, of course). Result: syntax error. hello.rb file Tried to open hello.rb via ruby in terminal
Oh yeah, I almost forgot: when I tried to open hello.rb in Files through another application, there was no Ruby script in the list (ruby or irb or at least something through which one could open a .rb file). No program for .rb format
I hope I have explained the problem in sufficient detail and clearly. And I hope for your help and understanding! In any case, good mood to you!
On Fedora & CentOS, the Ruby installation is split into many smaller packages. If you want to run irb, you'll also have to install the ruby-irb package using dnf install ruby-irb.

Rubyinstaller for Windows - ruby does nothing

I've tried using Ruby 2.0 x64 and Ruby 1.9.3 for Windows using RubyInstaller. Entering ruby -v works as expected, and running gem gives me the expected usage docs. Running and using the Interactive Ruby application works as expected. I am running Windows 8.1 Update.
However, for both installations, running ruby from cmd gives me a blank prompt where I can type, but nothing is executed when I press enter. If I attempt to install a gem, there is a similar issue where the program is running, but there is absolutely no output, and nothing happens.
I can't seem to be able to find a similar issue elsewhere. Does anyone know what might be wrong, and how I could fix it?
What did you expect to happen? ruby.exe is the ruby interpreter, meant for running ruby scripts. Normally, to use it you would create a file containing valid ruby commands with your favorite text editor (but not a word processor). If you save the file as foobar.rb, typing ruby foobar.rb (or if you told the installer to associate .rb files with ruby, typing just foobar.rb) will execute the commands in the file as a script/program. If you don't supply a script file name, ruby goes into input mode and expects you to type in a program on the spot. It won't give any feedback until you indicate end-of-file by typing CTRL-z, at which point it will process what you typed and most likely tell you about all the errors you made. If you want line-by-line interactive feedback, use irb.

Putting links to scripts in my cygwin bin

I have made a few python scripts, but is there an easier way to run them? I am using cygwin.
python "C:\Users\Desk\Dropbox\scripts\wsort.py" > data11414_unsorted.txt < data11414_sorted.txt
I want something like this (not typing the path name or "python"):
wsort > data11414_unsorted.txt < data11414_sorted.txt
where wsort is a link to my real wsort.py
Add a
Shebang
to the script
#!/bin/python
then invoke like this
wsort.py > data11414_unsorted.txt < data11414_sorted.txt
First, your question has a Windows-style path (backslashes, beginning with C:) rather than a Cygwin path (/cygdrive/c/Users/Desk/Dropbox/scripts/wsort.py). That implies you're not actually using Cygwin, or if you are, you're ignoring a bunch of warnings.
The below assumes you're using Cygwin Bash (which should be what you get if you start Cygwin Terminal from the Start Menu) and Cygwin Python (which you've installed using Cygwin's setup.exe, not a Windows Python installer). If your not, you're making life more difficult for yourself than you need to.
That out the way, there's a bunch of steps you need to take:
First, make the script executable. Use the chmod command for that, from a Cygwin Bash shell:
chmod +x /cygdrive/c/Users/Desk/Dropbox/scripts/wsort.py
Second, tell the system how to execute it. Add the following line to the top of the script:
#!/bin/python
(That's a "shebang". Python sees it as a comment, so doesn't do anything with it, but Cygwin and other Linux-like systems will use that line to see which program to run the script with. In this case, Python.)
Third, make sure your line endings are correct. Cygwin expects Linux line endings and will fail without them. This may not be a problem, but there's no harm in doing this. Run the following command:
dos2unix /cygdrive/c/Users/Desk/Dropbox/scripts/wsort.py
At this point, you'll be able to call the script by specifying the full path to it in Cygwin. You can't yet run it without specifying where the script is explicitly.
The fourth step is making sure the script is "in your path", ie in one of the folders where Cygwin looks for scripts to run. There are lots of ways to do this, but the most sensible is probably to just add your scripts directory to your path. The following command will add your scripts directory to your path whenever you start a new Cygwin session:
echo 'PATH="/cygdrive/c/Users/Desk/Dropbox/scripts:$PATH"' >>~/.bashrc
You will need to restart your Cygwin terminal for that to take effect, however.
At that point, you'll be able to run the script in Cygwin just by typing wsort.py (and thus use it with redirections and so forth as in your question).
Finally, to be able to call it simply as wsort, there's a number of options. The obvious one is just renaming the file. More usefully (and without copying the file or doing anything liable to break with Dropbox syncing things), try creating an alias:
echo 'alias wsort=wsort.py' >>~/.bashrc
Again, you'll need to restart your Cygwin terminal for that to take effect.
Maybe use an alias ?
alias wsort = "Command_Used"

Windows/cygwin shebang line

I am using Sphinx quite often. There is one index that calls a stored procedure with one param as input. The param can be any number from 1 to 10 and each returs different results. Since it would make sphinx config quite crowded, even with inheritance. So I thought I will use shebang line at the start of sphinx config file (stored as sphinx.py now). This works great in production enviroment since it runs on Ubuntu. But I want to run it on my local machine as well, but here is the problem called - Windows. Since I have cygwin as well, I tried to run it via cygwin, but it is the same - nothing happens.
I tried to run with both cygwin paths and windows paths, but both get ignored or treated as comments. From what I have read it should be working with cygwin. Could it be that it does not work since I have to call an exe file?
With:
$ ./indexer.exe sphinx.conf
I have tried to run it as perl script, bash script (via cygwin) and it gets ignored either way.
Is there a reliable way to run shebang lines on Windows? Or force cygwin to at least spit an error in my face... Even hacks are good since its just my development machine.
Any help is appreciated
All a shebang line does is tell the unix system() call what interpreter to use. If you specify indexer.exe then you are saying that you want it to use indexer.exe, so that is what it will use.
If you run Indexer.exe, indexer.exe will decide what to do.
Does Indexer.exe understand shebang lines? Or not?
Perl, as a convenience, will read the shebang line, and if it isn't Perl, it will and call the other program for you.
So maybe call Perl instead of Indexer, and it will do the right thing?

Is there a way to convert ruby scripts to executable(linuxmint)

Hey guys, I run LinuxMint and I have some scripts which I want to run without terminal, can you tell me how?
You need to:
Put as the first line of your ruby script the following shebang line (so bash knows what program to use to run this file)
#!/usr/bin/env ruby
Make your ruby file executable. In a console you can do this:
chmod 700 my_ruby_file.rb
Test that your ruby file is now executable. In a console write:
./my_ruby_file.rb
Notice that we are no longer calling "ruby my_ruby_file.rb", but instead just call the file directly "./my_ruby_file.rb"
If your ruby program executed normally, then everything is going well. If it does not execute and shows you an error, then something is not well done from the previous steps (and post your error)
In your desktop, create an application link, and point it to the my_ruby_file.rb
Once you have the application icon created and shown in your desktop, you can doble-clickit and it will run your application.
Tell us how it went- cheers

Resources