Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Do I Setup the Notepad++ Run Command for Ruby?

I'm trying to setup the Notepad++ IDE so that when I press F6 the Ruby script I'm editing will run. After searching the internet I've found that putting cmd /K ruby "$(FULL_CURRENT_PATH)" into the run dialogue box that pops up when I press F5 will run basic scripts in the Command Prompt (I'm using Windows 7).

However, if my code loads any external data such as .txt files, or as I've found with Gosu, loads any image files, Ruby complains that things do not exist which do in fact exist.

I know my code and Ruby installation (Ruby 1.9.3) are fine because prior to now I've been using FreeRIDE, an older, somewhat buggy IDE that I've grown tired of, and my code runs fine when I press F5 using that IDE.

Some examples of the complaints follow.

My Text Adventure:

C:/Users/Estanislao/Dropbox/Allway Sync/My Important Documents/Text Focused Fold
er/Ruby Scripts/Text Adventure/0.1.0/File Parser/DungeonContentFileParser.rb:8:i
n `initialize': No such file or directory - Example Dungeon Creator File.txt (Er
rno::ENOENT)
        from C:/Users/Estanislao/Dropbox/Allway Sync/My Important Documents/Text
 Focused Folder/Ruby Scripts/Text Adventure/0.1.0/File Parser/DungeonContentFile
Parser.rb:8:in `open'
        from C:/Users/Estanislao/Dropbox/Allway Sync/My Important Documents/Text
 Focused Folder/Ruby Scripts/Text Adventure/0.1.0/File Parser/DungeonContentFile
Parser.rb:8:in `encapsulate_method'
        from C:/Users/Estanislao/Dropbox/Allway Sync/My Important Documents/Text
 Focused Folder/Ruby Scripts/Text Adventure/0.1.0/File Parser/DungeonContentFile
Parser.rb:117:in `sort_room_data_external_method'
        from C:/Users/Estanislao/Dropbox/Allway Sync/My Important Documents/Text
 Focused Folder/Ruby Scripts/Text Adventure/0.1.0/File Parser/DungeonContentFile
Parser.rb:125:in `<main>'

D:\Programming Stuff\Notepad++>

My Gosu Program:

C:/Users/Estanislao/Dropbox/Allway Sync/My Important Documents/Text Focused Fold
er/Ruby Scripts/Game Development/Circular Motion.rb:10:in `initialize': Could no
t load image media/Space2.png using either GDI+ or FreeImage: Unknown error (Run
timeError)
        from C:/Users/Estanislao/Dropbox/Allway Sync/My Important Documents/Text
 Focused Folder/Ruby Scripts/Game Development/Circular Motion.rb:10:in `new'
        from C:/Users/Estanislao/Dropbox/Allway Sync/My Important Documents/Text
 Focused Folder/Ruby Scripts/Game Development/Circular Motion.rb:10:in `initiali
ze'
        from C:/Users/Estanislao/Dropbox/Allway Sync/My Important Documents/Text
 Focused Folder/Ruby Scripts/Game Development/Circular Motion.rb:181:in `new'
        from C:/Users/Estanislao/Dropbox/Allway Sync/My Important Documents/Text
 Focused Folder/Ruby Scripts/Game Development/Circular Motion.rb:181:in `<main>'

D:\Programming Stuff\Notepad++>

If anyone could lend any help at all I'd really appreciate it.

Update: knut's suggestions have allowed me to get what I want after some inconvenient juggling each time I start the program up. There are a few problems. Using

cmd /K "cd "$(CURRENT_DIRECTORY)" && ruby "$(FULL_CURRENT_PATH)"" 

in the default run dialogue does not work. (I get the same complaints as above.) But using NppExec and

cd "$(CURRENT_DIRECTORY)"
ruby "$(FULL_CURRENT_PATH)"

for that works fine, except with my Gosu code, which should draw a window and animate some images, nothing happens. However, if each time I start up Notepad++ I run the NppExec and then use the default run dialogue everything works correctly using the built in run command for that session. Any ideas to why all this occurs and how to prevent it? Also, I'd prefer to have Notepad++ open a Command Prompt window instead of running inside Notepad++ itself, as it does with NppExec. And thank you!

Update2: It appears that restarting my computer has cleared up the problem, yet now I'm more confused as to what is actually taking place. Is it the NppExec plugin that is actually allowing things to work as I wish, even though I'm using a saved script for the default run dialog? Or Is this a bug, that kept

cmd /K "cd "$(CURRENT_DIRECTORY)" && ruby "$(FULL_CURRENT_PATH)""

from working until I restarted?

like image 531
cyclingLinguist Avatar asked Oct 15 '12 20:10

cyclingLinguist


People also ask

How do I run a Ruby script in Notepad?

Most Ruby programs can be run from what is called “the command line.” You write your code in a plain text editor (like TextEdit or Notepad, or something more sophisticated like BBEdit or Notepad++), save it to a text file with an extension of . rb, then run “ruby yourprogram.

How do I run a ruby command?

Run a script Press Ctrl twice to invoke the Run Anything popup. Type the ruby script. rb command and press Enter . If necessary, you can specify the required command-line options and script arguments.

How do I open Ruby in CMD?

To start a command prompt on Windows, go to Start -> Run. In the dialog that appears, enter cmd into the input box and press OK. To start a command prompt on Ubuntu Linux, go to Applications -> Accessories -> Terminal. To start a command prompt on OS X, go to Applications -> Utilities -> Terminal.

How do I open Ruby console in Windows?

Open up IRB (which stands for Interactive Ruby). If you're using macOS open up Terminal and type irb , then hit enter. If you're using Linux, open up a shell and type irb and hit enter. If you're using Windows, open Interactive Ruby from the Ruby section of your Start Menu.


1 Answers

Your problem: With

cmd /K ruby "$(FULL_CURRENT_PATH)"

you call the ruby-script in the actual directory - and the actual directory must not be the directory of your source. In my test case it was the directory of Notepad++.

You may use:

cmd /K "cd "$(CURRENT_DIRECTORY)" && ruby "$(FULL_CURRENT_PATH)""

But I recommend to use the NppExec-Plugin. With NppExec you can define a command like:

cd "$(CURRENT_DIRECTORY)"
ruby "$(FULL_CURRENT_PATH)"

So you start your ruby script in the correct directory.

Or even easier:

You set the option Plugins->nppexec >follow $(current directory) and start NppExec with

ruby "$(FULL_CURRENT_PATH)"

Maybe also interesting:

  • http://docs.notepad-plus-plus.org/index.php?title=Compiling_Source_Code
like image 69
knut Avatar answered Sep 26 '22 03:09

knut