tags:

views:

39

answers:

2

I need to

  • run ant remotelly
  • create/modify xml files for ant
  • pass back results from ant's execution

so I thought I am going to write a web/application server in ruby. But I do not know where to start.

The computer that will run ant is Win XP SP3 and there is no web server or anything else running.

I found this code but not sure which part to modify so I does what I want. Let's say I want to run "dir" command and send back to the browser result of that command.

require 'socket'
webserver = TCPServer.new('127.0.0.1', 7125)
while (session = webserver.accept)
   session.print "HTTP/1.1 200/OK\r\nContent-type:text/html\r\n\r\n"
   request = session.gets
   trimmedrequest = request.gsub(/GET\ \//, '').gsub(/\ HTTP.*/, '')
   filename = trimmedrequest.chomp
   if filename == ""
      filename = "index.html"
   end
   begin
      displayfile = File.open(filename, 'r')
      content = displayfile.read()
      session.print content
   rescue Errno::ENOENT
   session.print "File not found"
   end
   session.close
end
+1  A: 

You can use ruby web server such as Rack, Webrick, mongrel, also you can use Ruby on Rails, Sinatra what else you want.

Of course you can write code from scratch, but it's not good idea to write whole by your own.

tisphie
+1  A: 

Ruby includes a Web server (WEBrick) so you don't actually need to use the code that you posted. Sinatra is designed specifically for writing very small Web applications - it lets you write a Web application in a few lines of code and automatically uses the provided Web server.

Stuart Ellis
@Stuart Ellis: sounds good. I cannot find any example I would use. Any sample of app where there would be a html page with links and each link means that ruby would call an external program?
Radek
this is what I was looking fooooor http://net.tutsplus.com/tutorials/ruby/an-introduction-to-haml-and-sinatra/ (thanks Tim)
Radek
@Radek: One thing that I would say that isn't in that article: developing a Sinatra application is much faster and more pleasant if you use Shotgun. This automatically reloads your code each time that you save a change, so that you don't have to start and stop the application every time that you edit something.
Stuart Ellis