[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Command Line Automation?

Joseph Taylor

4/23/2006 1:27:00 AM

Hi,

I'm interested in automating user input at the command line.
Specifically, I'd like to "cheat" in a text based adventure game
(dunnet for emacs). I'm a complete novice, and although I'm sure this
is possible, I'd appreciate suggestions as to where I should learn how.

It's not that I'd like to skip the basics, but rather I learn best by
doing - and I do enjoy the gratification culled from a marginally
useful toy program.

Thanks!

2 Answers

James Herdman

4/23/2006 4:15:00 AM

0

Hey there!

If I were you I'd start with a tutorial here http://tryruby....
-- it's fully interactive and gets the basics going. Now, as for a
game, you might want to try this tutorial
http://poignantguide... and work your way up to this one
http://poignantguide.ne... (the last one is a game of sorts).

Now, as for cheating... I'm not entirely sure how Emacs works, but you
might be able to run it from within a script and analyze the output
stream (standard output). It'd take a lot of work, but it could be
fun!

Some other folks here might have better toy program tutorials. Alas, I
do not. If you can, work your way through the basics in some of these
tutorials. I found it quite rewarding.

Best of luck,

James H.

Daniel Seix

4/23/2006 9:17:00 AM

0

JoeKarma@gmail.com escribió:

> Hi,
>
> I'm interested in automating user input at the command line.
> Specifically, I'd like to "cheat" in a text based adventure game
> (dunnet for emacs). I'm a complete novice, and although I'm sure this
> is possible, I'd appreciate suggestions as to where I should learn how.
>
> It's not that I'd like to skip the basics, but rather I learn best by
> doing - and I do enjoy the gratification culled from a marginally
> useful toy program.
>
> Thanks!

If on UNIX and with PTY98 support, this is a starting point:

#!/usr/bin/env ruby

require 'pty'
require 'expect'

$expect_verbose = true
help_msg = ""

PTY.spawn("emacs -batch -l dunnet") do |reader, writer, pid|
reader.expect('>')
writer.puts('help')

begin c = reader.getc.chr
help_msg << c
end while c != '>'

writer.puts('quit')
end

puts "This is the help message: #{help_msg}"