how can i create a .bat file which can run ruby

save a text file as blah.bat

in the file type

ruby myfile.rb

save, run and smile :slight_smile:

regards

I would guess that ruby isn’t properly installed…or not installed at all, apart from instantRails.

if you type “ruby -v” in a cmd you should get a line telling you which version of ruby you have installed…

instantrails contains ruby so that rails applications can run in the instantrails sandbox, but it does not install as a os wide application/service…I’m out of my depth with the vocab. Basically, if you download and install ruby

http://rubyforge.org/frs/?group_id=167

it will install and you will be able to run ruby anywhere in a command line.

The problem your are having is because of one of the features of
Instant Rails: the fact that it does not modify your system
environment. IR's ruby\bin directory is not on your system path (as it
would be with a normal Ruby installation).

If you don't plan to move IR at all (for example, you don't have it on
a flash drive), then the simplest thing would be to put IR's ruby\bin
on the path.

Another alternative would be to put your bat file in IR's ruby\bin
directory and then at runtime use the path to the bat file to
construct a path to ruby\bin\ruby.exe. For examples of doing this,
look at the bat files already in the ruby\bin directory.

Curt

David wrote:

Ruhul Amin wrote:
  

Ivor Paul wrote:
    

save a text file as blah.bat

in the file type

ruby myfile.rb

save, run and smile :slight_smile:

regards
      

thanks for ur reply . but I tried it but error was

"ruby" command not found.
so i guess, i have to first run the ruby.exe and then then run the file
by ruby.

am I right? if yes then how can I do this?

Amin
    
Perhaps the path to your ruby.exe is not included in your PATH
environment variable in Windows. If so, either edit your PATH to include
it, or else add the full path to the ruby.exe to your batch file:

c:\InstantRails\bin\ruby.exe myfile.rb

[Your actual path may vary from that shown above]

This should help you, it's from my .bat files that run ruby scripts. Of course, fix the paths to match yours.

<code>
echo off
cls

REM Set up the environment variables for the script
set PATH_TO_RUBY=D:\InstantRails\ruby\bin
set RUBY=%PATH_TO_RUBY%\ruby.exe
set PATH_TO_SCRIPTS=F:\Projects\autoscripts

%RUBY% %PATH_TO_SCRIPTS%\MyRubyScript1.rb
%RUBY% %PATH_TO_SCRIPTS%\MyRubyScript2.rb
%RUBY% %PATH_TO_SCRIPTS%\MyRubyScript3.rb

</code>

If you want it to be something that starts asynchronously (in the sense that it starts in a separate Command window and does not hold up the original .bat file which is starting your script, you could also use:

<code>
start %RUBY% %PATH_TO_SCRIPTS%\AnotherScript.rb
</code>

Hope this helps!
Cheers
Mohit.

thanks for clarifying that for me as well!