I can't run a ruby file in sublime Text 3

When I try to run my file with the "build" option in sublime text it tells me "building" and then just stops. I don't get an error message and it doesn't crash, it works fine to edit the code. It just doesn't run it at all. It worked when I didnt use "def" as command but I have to use them for a school project and it doesnt work at all. Edit: It does work with def but it doesnt work when I try to get user input.

Upvotes: 0

Views: 264

Answers (1)

rtxndr
rtxndr

Reputation: 932

If you are using Windows OS:

1. Create launcher batch file C:\Ruby26-x64\RBCMDRUN.BAT

@echo off

TITLE %1
set EXE=%~dp0bin\ruby.exe
set MYARGS=
:NEXTARG
  if "[%~1]" NEQ "[]" (
      IF "[%~1]" EQU "[-PAUSE]" (
        set ALWAYSPAUSE=Y
        shift
        goto NEXTARG
      )
      if "%MYARGS%" EQU "" (
        set MYARGS=%~1
      ) else (
        set MYARGS=%MYARGS% %~1
      )
      rem echo %MYARGS%
      if not "[%~1]"=="[]" (
        shift
        goto NEXTARG
      )
  )

IF "[%MYARGS%]" EQU "[]" (
    ECHO Error: ruby file name is missing
    GOTO PAUSEANDEXIT
)

echo %EXE% %MYARGS%
%EXE% "%MYARGS%"

IF %ERRORLEVEL% NEQ 0 (
    ECHO Program exited with error %ERRORLEVEL% 
    GOTO PAUSEANDEXIT
)

IF "%ALWAYSPAUSE%" NEQ "Y" GOTO EXIT

:PAUSEANDEXIT
PAUSE
:EXIT
EXIT

2. Add or Modify .sublime-build for Ruby

Packages/Ruby/Ruby.sublime-build

    "cmd": ["start", "C:\\Ruby26-x64\\RBCMDRUN.BAT", "$file", "-PAUSE"],
    "shell": true,

Remove "-PAUSE" if you don't need it.

3. [Optional] Bind a key for running your script

Preferences - key bindings

{ "keys": ["f5"], "command": "build"},

Upvotes: 1

Related Questions