[TxMt] Input from gets in Ruby

Kumar McMillan kumar.mcmillan at gmail.com
Thu Sep 29 17:50:57 UTC 2005


> > stdout window.  However, I can't figure out how to get input from
> > the gets method.  Is there any way to read from stdin when running
> > a Ruby script from the Run Command>Ruby>Run Ruby menu?
>
> Yes, this happens automatically, but stdin is redirected to read
> input from a dialog which should pop up whenever your script does a
> gets or similar.

Interesting.  I didn't know about this feature.  But I just tried it
and stdin was sent as en empty string; there was no dialog.  How do
you have to set the command up?  My test was like this:

Save=Nothing
Command=
#!/usr/bin/env python

import sys
for line in sys.stdin.readlines():
    print line
print "done"

Input=None
Output=Show in separate window

obviously this same script run in the shell will wait for input and
will finish when you send it ^D (end of file).  I tried it with
readline too, but the same thing: no dialog and just an empty string. 
Like :

#!/usr/bin/env python

import sys
print sys.stdin.readline().strip()
print "done"



More information about the textmate mailing list