Prev: Showing pictures in GTK::IconView
Next: It's a fact not lost on the opportunity to see yourself
From: Sask Khan on 29 Mar 2010 16:27 All, Just started Ruby and using Notepad++ for writing code but for some reason, upon execution of the *.rb file, the command prompt give me the attached error (please see the image attached). The file is just a text file called 'text.txt', which is sitting in the same folder as the ruby script file. Im confused... Secondly, why is the answer '555' to the registration question... I think Im confused by the '11', which I thougth either should be read an a string or a normal number. Can anyone shed some light on this please... Cheers, Attachments: http://www.ruby-forum.com/attachment/4629/RudyError.jpg -- Posted via http://www.ruby-forum.com/.
From: Roger Pack on 29 Mar 2010 16:42 Sask Khan wrote: > All, > > Just started Ruby and using Notepad++ for writing code but for some > reason, upon execution of the *.rb file, the command prompt give me the > attached error (please see the image attached). > > The file is just a text file called 'text.txt', which is sitting in the > same folder as the ruby script file. Im confused... You'll need to run "ruby" from the same directory where 'text.txt' is located. -rp -- Posted via http://www.ruby-forum.com/.
From: Sask Khan on 29 Mar 2010 16:48 Roger Pack wrote: > You'll need to run "ruby" from the same directory where 'text.txt' is > located. > -rp Roger, what do you mean? Ruby.exe is sitting in C:\Program Files\Ruby\Bin\ruby.exe, am I to copy the script and the txt file to that folder in order to run this? -- Posted via http://www.ruby-forum.com/.
From: Daniel Frank on 29 Mar 2010 17:50 Sask Khan wrote: > Roger Pack wrote: >> You'll need to run "ruby" from the same directory where 'text.txt' is >> located. >> -rp > > Roger, what do you mean? Ruby.exe is sitting in C:\Program > Files\Ruby\Bin\ruby.exe, am I to copy the script and the txt file to > that folder in order to run this? No. Add the following line on the top of your script: Dir.pwd This will show you in which working directory ruby was started from. Guessing from the screenshot I assume it will be C:\Program Files\Notepad++. Since you did not specify the path of test.txt, ruby will try to open a file test.txt in that directory. There are a couple of ways around: a) Change the working directory before you start ruby. For example open a command prompt, enter "cd /d g:\docs\l_ruby", then run the script: "ruby analyzer.rb" b) Change the working directory after you start ruby. Add a line before your "File.read...." line: Dir.chdir("g:/docs/l_ruby") That will change the working directory to the one that contains the test.txt file. c) Figure out how to change the working directory that Notepad++ starts ruby in. I have no idea how to do this. I hope this will get you back on the track again. I suggest you have a look at http://en.wikipedia.org/wiki/Working_directory to learn what a working directory is, if you don't know already. It's essential to know when writing scripts. -- Posted via http://www.ruby-forum.com/.
From: Sask Khan on 30 Mar 2010 01:29 Daniel, Thanks much for the help & guidance. Thats a wonderful start and atleast now I know where to look. best, Daniel Frank wrote: > No. > Add the following line on the top of your script: > Dir.pwd > This will show you in which working directory ruby was started from. > Guessing from the screenshot I assume it will be C:\Program > Files\Notepad++. > Since you did not specify the path of test.txt, ruby will try to open a > file test.txt in that directory. > There are a couple of ways around: > a) Change the working directory before you start ruby. For example open > a command prompt, enter "cd /d g:\docs\l_ruby", then run the script: > "ruby analyzer.rb" > b) Change the working directory after you start ruby. Add a line before > your "File.read...." line: > Dir.chdir("g:/docs/l_ruby") > That will change the working directory to the one that contains the > test.txt file. > c) Figure out how to change the working directory that Notepad++ starts > ruby in. I have no idea how to do this. > I hope this will get you back on the track again. I suggest you have a > look at http://en.wikipedia.org/wiki/Working_directory to learn what a > working directory is, if you don't know already. It's essential to know > when writing scripts. -- Posted via http://www.ruby-forum.com/.
|
Pages: 1 Prev: Showing pictures in GTK::IconView Next: It's a fact not lost on the opportunity to see yourself |