我正在尝试设置 Notepad++ IDE,这样当我按 F6 时,我正在编辑的 Ruby 脚本就会运行。在互联网上搜索后,我发现把
cmd/K ruby "$(FULL_CURRENT_PATH)"
进入当我按 F5 时弹出的运行对话框将在命令提示符中运行基本脚本(我使用的是 Windows 7)。
但是,如果我的代码加载任何外部数据,例如 .txt 文件,或者正如我在 Gosu 中发现的那样,加载任何图像文件,Ruby 会提示实际上存在的东西不存在。
我知道我的代码和 Ruby 安装 (Ruby 1.9.3) 都很好,因为在此之前我一直在使用 FreeRIDE,这是一个我已经厌倦的较旧的、有点错误的 IDE,当我使用时我的代码运行良好使用该 IDE 按 F5。
投诉的一些例子如下。
我的文字冒险:
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++>
我的 Gosu 程序:
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++>
如果有人能提供任何帮助,我将不胜感激。
更新:knut 的建议让我在每次启动程序时都经历了一些不便的杂耍之后得到了我想要的东西。有几个问题。使用
cmd /K "cd "$(CURRENT_DIRECTORY)" && ruby "$(FULL_CURRENT_PATH)""
在默认运行对话框中不起作用。 (我收到与上述相同的投诉。)但是使用 NppExec 和
cd "$(CURRENT_DIRECTORY)"
ruby "$(FULL_CURRENT_PATH)"
因为它工作正常,除了我的 Gosu 代码,它应该绘制一个窗口并为一些图像设置动画,但没有任何反应。但是,如果我每次启动 Notepad++,我都会运行 NppExec,然后使用默认运行对话框,使用该 session 的内置运行命令一切正常。关于为什么会发生这一切以及如何预防的任何想法?此外,我更喜欢让 Notepad++ 打开一个命令提示符窗口,而不是像 NppExec 那样在 Notepad++ 内部运行。谢谢!
更新 2: 重新启动计算机似乎解决了问题,但现在我对实际发生的事情更加困惑。是 NppExec 插件实际上允许事情按照我的意愿工作,即使我为默认运行对话框使用保存的脚本?或者这是一个错误,保持
cmd /K "cd "$(CURRENT_DIRECTORY)" && ruby "$(FULL_CURRENT_PATH)""
从工作到重新开始?
最佳答案
你的问题:用
cmd /K ruby "$(FULL_CURRENT_PATH)"
您在实际目录中调用 ruby 脚本 - 实际目录不能是您的源目录。在我的测试用例中,它是 Notepad++ 的目录。
您可以使用:
cmd /K "cd "$(CURRENT_DIRECTORY)" && ruby "$(FULL_CURRENT_PATH)""
但我建议使用 NppExec-Plugin。 使用 NppExec,您可以定义如下命令:
cd "$(CURRENT_DIRECTORY)"
ruby "$(FULL_CURRENT_PATH)"
所以你在正确的目录中启动你的 ruby 脚本。
或者更简单:
您设置选项 Plugins->nppexec >follow $(current directory)
并使用
ruby "$(FULL_CURRENT_PATH)"
也许也很有趣:
关于ruby - 如何为 Ruby 设置 Notepad++ 运行命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12903709/