5

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?

1 Answer 1

7

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:

1
  • the cd commmand should also use the /D switch. otherwise it would only work if the current file is on the same drive as notepad! so the full command is: cmd /K "cd /D "$(CURRENT_DIRECTORY)" && ruby "$(FILE_NAME)""
    – TmTron
    Oct 17, 2013 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.