Attaching a script to IO

A

Ari Brown

Hey all,
I'm trying to attach a script's output to IO (a socket. Is IO
the right term?)
I currently use a GServer script to accept connections from localhost.

I don't know if that made sense, but is there any way to change the
default output to my socket output?

Thanks,
---------------------------------------------------------------|
~Ari
ruby 1.8.6 (2007-03-13 patchlevel 0) [powerpc-darwin8.10.0]
 
A

Ari Brown

Oh, and if it makes a difference, information on using sockets with
Highline (Thanks, james!) would be GREATLY appreciated.


Hey all,
I'm trying to attach a script's output to IO (a socket. Is IO
the right term?)
I currently use a GServer script to accept connections from localhost.

I don't know if that made sense, but is there any way to change the
default output to my socket output?

Thanks,
---------------------------------------------------------------|
~Ari
ruby 1.8.6 (2007-03-13 patchlevel 0) [powerpc-darwin8.10.0]

-------------------------------------------|
Nietzsche is my copilot
 
M

Michael Gorsuch

Hey all,
I'm trying to attach a script's output to IO (a socket. Is IO
the right term?)

Works for me!
I currently use a GServer script to accept connections from localhost.

Well, can you just send whatever you need to send via puts?

Example:

class MyThingy < GServer
def initialize(port=3000, *args)
super(port, *args)
end
def serve(io)
io.puts "Hello!"
end
end

I don't know if that made sense, but is there any way to change the
default output to my socket output?

Thanks,
---------------------------------------------------------------|
~Ari
ruby 1.8.6 (2007-03-13 patchlevel 0) [powerpc-darwin8.10.0]
 
A

Ari Brown

Well, can you just send whatever you need to send via puts?

Example:

class MyThingy < GServer
def initialize(port=3000, *args)
super(port, *args)
end
def serve(io)
io.puts "Hello!"
end
end

Well, except I'm not trying to send "hello". I'm trying to keep my
script nice and clean, so I have a bunch of ugly code in a separate
file (which I call with require) and a method test(). If I pass io
as an argument with test:

def serve(io)
test(io)
end

and then later in test(io) have

io.puts

will the variable scope allow that?

Or should I find a way to reroute $stdout?

thanks,
ari
-------------------------------------------|
Nietzsche is my copilot
 
R

Robert Klemme

Well, except I'm not trying to send "hello". I'm trying to keep my
script nice and clean, so I have a bunch of ugly code in a separate file
(which I call with require) and a method test(). If I pass io as an
argument with test:

def serve(io)
test(io)
end

and then later in test(io) have

io.puts

will the variable scope allow that?

Or should I find a way to reroute $stdout?

It seems you want your script to act as a _server_. In that case class
TCPServer will help you. Please have a look:

http://www.ruby-doc.org/docs/ProgrammingRuby/html/lib_network.html

Kind regards

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,265
Latest member
TodLarocca

Latest Threads

Top