Stephan Kš╬per wrote:

> Hi all,
>
> I have the following problem both Win2K and Win98SE:
>
> On the Win2K box the following line works fine (and echoes the name of
> the host)
>
> puts `hostname`
>
> But other commands like "dir", "cd" and the like don't work... What I
> get is, eg.:
>
> C:\script.rb:1: command not found: dir
>
> with "script.rb" containing the line:
>
> puts `dir
>
> Strangely
>
> puts `dir *`
>
> doesn't complain about missing commands - but doesn't work either (that
> is nothing returned).
>

The problem is that commands like "dir" and "cd" are not programs, they
are built-in shell commands in command.com. When you run something with
backticks, ruby is using the stdlib call system(), which executes a
program with arguments.

To get "dir", "cd", and so forth to work, you'll need to do something like
this:

puts `command /c dir`
puts `command /c cd\\toast`

or whatever.

This isn't really a ruby thing, though. If you were writing this in C,
you'd have to do the same thing when calling the system() command.

Nor is it totally a Windows/DOS thing, if you wanted to call a built-in
ksh function in unix in Ruby, you'd probably have to do something like
this if ksh wasn't your default shell:

puts `ksh -c some command`

Anyway, I'm writing this from a horrible mail client, so forgive the
strange formatting. (= Hope that you can get it working!

--
Wes Landaker - wjl / mindless.com