Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 778
  • Last Modified:

Ruby - InputBox

Hello
Is it possible to get user input by using an Input Box e.g
Does a file exists - my code is as follows ........
puts "The file you are looking for does exist" if File.exist?("c:/Phil.txt")
.... then maybe get a message box to give the answer
I would like to get the user to enter c:/Phil.txt - is this possible and how

Regards
Phil

0
philsivyer
Asked:
philsivyer
1 Solution
 
Geert BormansCommented:
what do you mean with mesage box?
is this command line, web based or do you envisage to build a gui?
0
 
philsivyerAuthor Commented:
Command Line
0
 
Geert BormansCommented:
try something like this

#puts the question
puts "Add a filename here:"

# read a line from the commandline
str1 = STDIN.gets

#test for file existence (write logic yourself)

#echo
puts "#{str1} does exist"
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Geert BormansCommented:
note that you can use the FileTest module for checking the existence of the file

#puts the question
puts "Add a filename here:"

# read a line from the commandline
str1 = STDIN.gets

#test for file existence
flag = FileTest::exists?(str1.strip)
#echo
if flag then
      puts "#{str1.strip} does exist"
else
      puts "#{str1.strip} does NOT exist"
end

cheers

Geert
0
 
philsivyerAuthor Commented:
Geert
When I run the code it opens a command screen and does not allow me to make an entry.
Phil
0
 
Geert BormansCommented:
try running it in a commandscreen already
ruby mycode.rb
0
 
philsivyerAuthor Commented:
OK - it does not like it from ScITE - any ideas?

Phil
0
 
Geert BormansCommented:
I wouldn't know how to get that working from within SciTE
I will look at it tonight
0
 
philsivyerAuthor Commented:
Thanks
0
 
Geert BormansCommented:
SciTE is for development by the way, is there a reason why you want to launch a program this way, other than for debugging?
0
 
philsivyerAuthor Commented:
Not really - I guess it's easier for me to cut and paste etc - and visually it looks easier on the eye.

Phil
0
 
wesgarrisonCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup Zone:
Accept gertone's comment 20374555 as answer

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

wesgarrison Experts Exchange Cleanup Volunteer
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now