# Finer Command Line Control?

**URL:** <https://www.ruby-forum.com/t/finer-command-line-control/57236>\
**Category:** Ruby\
**Created:** [April 8, 2006, 10:49am UTC](https://www.ruby-forum.com/t/finer-command-line-control/57236 "2006-04-08T10:49:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Barrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/90db22/32.png) [@Alex\_Barrett](https://www.ruby-forum.com/u/Alex_Barrett)\
**Post date:** [April 8, 2006, 10:49am UTC](https://www.ruby-forum.com/t/finer-command-line-control/57236/1 "2006-04-08T10:49:35Z")

</div>

Is there any way to gain greater control of the command line in ruby? I  
know it’s usually possible to send special characters to send the output  
to a specific location, but I can’t seem to work it out.  
Forgive me if I’m overlooking the obvious; Nuby here 🙂

P.S. I’m on Windows. I imagine that could figure strongly here.

---

<div class="post-metadata">

**Author:** ![Alex\_Barrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/90db22/32.png) [@Alex\_Barrett](https://www.ruby-forum.com/u/Alex_Barrett)\
**Post date:** [April 8, 2006, 12:52pm UTC](https://www.ruby-forum.com/t/finer-command-line-control/57236/2 "2006-04-08T12:52:38Z")

</div>

Alexandru E. Ungur wrote:

> For saving the output, you can simply redirect it to the desired  
> location using ‘\>’, like this:

Sorry, my bad. When I said to a specific location I meant to a certain  
area in the console, i.e. Overwriting output I’ve already sent. Is there  
a way to do this in Ruby/Windows?

---

<div class="post-metadata">

**Author:** ![Alex\_Barrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/90db22/32.png) [@Alex\_Barrett](https://www.ruby-forum.com/u/Alex_Barrett)\
**Post date:** [April 8, 2006, 12:07pm UTC](https://www.ruby-forum.com/t/finer-command-line-control/57236/3 "2006-04-08T12:07:09Z")

</div>

> > > sender: “Alex Barrett” date: “Sat, Apr 08, 2006 at 05:49:39PM +0900” \<\<\<EOQ  
> > > Is there any way to gain greater control of the command line in ruby? I  
> > > know it’s usually possible to send special characters to send the output  
> > > to a specific location, but I can’t seem to work it out.  
> > > Forgive me if I’m overlooking the obvious; Nuby here 🙂
> 
> P.S. I’m on Windows. I imagine that could figure strongly here.  
> Command line ‘belongs to’ the command interpreter not to Ruby, so what  
> you’re actually asking is ‘what can your windows commandline do’ for  
> you, right? 🙂

For saving the output, you can simply redirect it to the desired  
location using ‘\>’, like this:

```
ruby.exe myscript.rb > c:\somefile.txt

```

More on redirection here (though UNIX specific, it does apply to windows  
as well): [Redirection (computing) - Wikipedia](http://en.wikipedia.org/wiki/Redirection_%28Unix%29)

Good luck,  
Alex

---

<div class="post-metadata">

**Author:** ![Alex\_Barrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/90db22/32.png) [@Alex\_Barrett](https://www.ruby-forum.com/u/Alex_Barrett)\
**Post date:** [April 8, 2006, 4:48pm UTC](https://www.ruby-forum.com/t/finer-command-line-control/57236/4 "2006-04-08T16:48:41Z")

</div>

Alex Barrett wrote:

> Alexandru E. Ungur wrote:
> 
> > For saving the output, you can simply redirect it to the desired  
> > location using ‘\>’, like this:
> 
> Sorry, my bad. When I said to a specific location I meant to a certain  
> area in the console, i.e. Overwriting output I’ve already sent. Is there  
> a way to do this in Ruby/Windows?

Such as printing a backspace character?

puts “\b”

---

<div class="post-metadata">

**Author:** ![Alex\_Barrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/90db22/32.png) [@Alex\_Barrett](https://www.ruby-forum.com/u/Alex_Barrett)\
**Post date:** [April 8, 2006, 5:58pm UTC](https://www.ruby-forum.com/t/finer-command-line-control/57236/5 "2006-04-08T17:58:33Z")

</div>

James B. wrote:

> Such as printing a backspace character?
> 
> puts “\b”

Heh, thanks. So simple. It’s a bit cumbersome, but it’ll do.

Craig K. wrote:

> Optionally, you can use the curses library if you don’t  
> want to embedded a bunch of escape sequences, which you will have to  
> figure out.

I’m on windows so no curses. At least, I get an error if I try 🙂

---

<div class="post-metadata">

**Author:** ![Alex\_Barrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/90db22/32.png) [@Alex\_Barrett](https://www.ruby-forum.com/u/Alex_Barrett)\
**Post date:** [April 8, 2006, 4:54pm UTC](https://www.ruby-forum.com/t/finer-command-line-control/57236/6 "2006-04-08T16:54:44Z")

</div>

You will need to have ANSI terminal control sequences to place your  
cursor  
where you want. Optionally, you can use the curses library if you don’t  
want to embedded a bunch of escape sequences, which you will have to  
figure out.

On the other hand, if you wish to overwrite something on the same line,  
you can use the backspace to back up to where you want and write what  
you  
want.

–Craig

---

<div class="post-metadata">

**Author:** ![Alex\_Barrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/90db22/32.png) [@Alex\_Barrett](https://www.ruby-forum.com/u/Alex_Barrett)\
**Post date:** [April 9, 2006, 3:44am UTC](https://www.ruby-forum.com/t/finer-command-line-control/57236/7 "2006-04-09T03:44:09Z")

</div>

Alex Barrett wrote:

> I’m on windows so no curses. At least, I get an error if I try 🙂

In my efforts to get Diakonos running under Windows (without Cygwin), I  
was able to get curses to go, so I can at least tell you it’s possible.  
I don’t remember the details. That is, I don’t remember if the  
one-click installer has it already, or if I had to download extra  
material.

HTH;  
Pistos

---

<div class="post-metadata">

**Author:** ![Alex\_Barrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/90db22/32.png) [@Alex\_Barrett](https://www.ruby-forum.com/u/Alex_Barrett)\
**Post date:** [April 8, 2006, 8:35pm UTC](https://www.ruby-forum.com/t/finer-command-line-control/57236/8 "2006-04-08T20:35:47Z")

</div>

On Sun, 2006-04-09 at 00:58 +0900, Alex Barrett wrote:

> Craig K. wrote:
> 
> > Optionally, you can use the curses library if you don’t  
> > want to embedded a bunch of escape sequences, which you will have to  
> > figure out.
> 
> I’m on windows so no curses. At least, I get an error if I try 🙂

I remember last time I used DOS, you had to set up a device driver  
(ANSI.SYS I believe) if you wanted to use ANSI terminal codes. If you  
loaded that, you got the full set.

Oh, according to Wikipedia, Windows now has built in support, so you  
could maybe try that…

> **[ANSI escape code](https://en.wikipedia.org/wiki/ANSI_escape_code)**
>
> ANSI escape sequences are a standard for in-band signaling to control cursor location, color, font styling, and other options on video text terminals and terminal emulators. Certain sequences of bytes, most starting with an ASCII escape character and a bracket character, are embedded into text. The terminal interprets these sequences as commands, rather than text to display verbatim.
> ANSI sequences were introduced in the 1970s to replace vendor-specific sequences and became widespread in the ...

[http://rrbrandt.dyndns.org:60000/docs/tut/redes/ansi.php](http://rrbrandt.dyndns.org:60000/docs/tut/redes/ansi.php)

---

<div class="post-metadata">

**Author:** ![Alex\_Barrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/90db22/32.png) [@Alex\_Barrett](https://www.ruby-forum.com/u/Alex_Barrett)\
**Post date:** [April 9, 2006, 6:16am UTC](https://www.ruby-forum.com/t/finer-command-line-control/57236/9 "2006-04-09T06:16:08Z")

</div>

DÅ?a Sobota 8. AprÃ­l 2006 17:58 Alex Barrett napÃ­sal:

> I’m on windows so no curses. At least, I get an error if I try 🙂

Hmm, aren’t you just missing the DLL? PDcurses should work in that case,  
unless my memory fails me.

David V.
