PDA

View Full Version : Opening a File in Ruby


zylon
August 24th, 2007, 08:28 PM
Ok I've been trying to figure this out for a while, and all my attempts have failed.

Does anyone know what function/code opens a file?
I know in batch it is
GOTO C:\Program Files\ijji\ENGLISH\Gunz\Gunz.exe
to open a file in this case Gunz: The Duel aka A game. But how would I open a file on Ruby? someone please help me.

Much appreciated.

zylon
October 4th, 2007, 09:38 PM
Hello? can anyone help me!! please :(

rob
October 5th, 2007, 05:33 PM
In Ruby you do:

system("program.exe")

Replace program.exe with what you want to run.

[H4z3]
October 9th, 2007, 09:19 AM
Saying you want to open a file means you want to actually OPEN it, and not run it..

Of course an executable can also be open and read in as binary..

bytes = open('MyApp.exe', 'rb').read
open('file.txt:MyApp.exe', 'wb') do |f|
f.write(bytes)
end

This is an example of opening a file.. Go with rob's example if you want to run the program..

rob
January 9th, 2008, 02:40 AM
Sorry for the confusion there, I thought you wanted to run the program, not open the file.