views:

38

answers:

2

Hi there,

I'm building a console application in Ruby. One of the things I'd like it to do is edit text files. It strikes me that the most reasonable course of action would be to launch whatever default editor the user has set up -- nano, vi, emacs... let the user decide. I'd like to pass it the name of the file that will be created/edited.

I've investigated various methods, including the backticks like so:

response = `nano *nameoffile*`

And I've also tried using the POpen4 Ruby gem, which also doesn't seem to do anything.

I suspect these methods are strictly for common, non-shell-type applications that immediately return a result, and editors like nano require a different technique? Your feedback is much appreciated!

Cheers,

Aaron.

A: 

You might want to take a look at interactive_editor, they do something like that.

Tass
Yes! I had to hack their gem a bit, but yes, it does exactly what I need. Thanks so much!
Aaron Vegh
For posterity's sake, if anyone needs interactive_editor in a console app without having the text file eval()'d, I've forked the github project here: http://github.com/aaronvegh/console_editor
Aaron Vegh
+1  A: 

Also you can use

system "nano #{your_file_name}"
Lavir the Whiolet