The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Ruby for Windows in Under 1K

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Red Handed

Posts: 1158
Nickname: redhanded
Registered: Dec, 2004

Red Handed is a Ruby-focused group blog.
Ruby for Windows in Under 1K Posted: Dec 17, 2005 1:20 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Red Handed.
Original Post: Ruby for Windows in Under 1K
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Red Handed
Latest Posts From RedHanded

Advertisement

If you enjoyed Rubyless Ruby, here’s a remix for Windows. I’m using the Windows Scripting Host for this one, which means an appearance from good ol’ XmlHttpRequest. It’s the first new wave of 2006: Ajax for Batch Files, peoepl!

Here’s the code, I’ll show ya how to run it after the jump.

 tryurl = "http://tryruby.hobix.com/irb?cmd=" 

 // strap on xhr, nice, nice
 function wget( url, hdrs ) {
   var http = WScript.CreateObject( "Microsoft.XMLHTTP" );
   http.open( "GET", url, false );
   for ( var k in hdrs ) {
     http.setRequestHeader( k, hdrs[k] );
   }
   http.send( "" );
   return http.responseText;
 }

 // the prompt!
 sess = wget( tryurl + escape( "!INIT!IRB!" ), {} )
 WScript.Echo( "Interactive Ruby ready." )
 WScript.StdOut.Write( ">> " )
 WScript.StdIn.Read(0)
 while ( true ) {
   cmd = WScript.StdIn.ReadLine()
   resp = ""; ps = ">>";
   if ( cmd ) {
     resp = wget( tryurl + escape( cmd ).replace( '+', '%2B' ), 
                 {'Cookie': '_session_id=' + sess});
     ps = "..";
     if ( resp ) {
       WScript.StdOut.Write( resp );
       ps = ">>";
     }
   }
   WScript.StdOut.Write( ps + " " );
 }

You can download the script try.js by doing a right-click Save as... in IE. To run the thing from the prompt:

 cscript /Nologo try.js

While the Windows Scripting Host has probably been the number one source of viruses for the platform (ILOVEYOU comes to mind), it’s actually a very natural way to shell script. Many years ago there was a brilliant desktop shell called Graphite which had WSH hooks. It’s too bad that lots of stuff is buried in obscure objects.

For the above script, I found the ss64 reference to be the most practical reference. And JS/XHR docs are wide and far, of course.

Read: Ruby for Windows in Under 1K

Topic: Varnish Dry on Wink'd 1.6 Previous Topic   Next Topic Topic: ActiveRecord Migrations Presentation Slides Available

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use