[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

ruby bring up cmd prompt windows

arose

6/12/2006 6:38:00 PM

What would I have to do to get Ruby to do the equivalent of typing cmd
in Windows Run and then interacting with the command prompt?

I'm looking at some automation of running commands from the dos prompt.

12 Answers

Tim Hoolihan

6/12/2006 7:03:00 PM

0

if you use commands that are native to the command line, the window will
come up.

For instance, put the following in a .rb file and double click it:

#!ruby.exe -w
#cmdlinetest.rb
pwd=`cd`
puts "current directory:#{pwd}"
user=`whoami`
puts "you are logged in as:#{user}"
exit if gets


arose wrote:
> What would I have to do to get Ruby to do the equivalent of typing cmd
> in Windows Run and then interacting with the command prompt?
>
> I'm looking at some automation of running commands from the dos prompt.
>

arose

6/14/2006 8:07:00 PM

0

Ok I half way understand what you are saying, I'm experimenting..

I haven't used the ` character yet in Ruby
Have time to explain it to me?

You have responded to a large number of my elementary questions,
thanks.



Tim Hoolihan wrote:
> if you use commands that are native to the command line, the window will
> come up.
>
> For instance, put the following in a .rb file and double click it:
>
> #!ruby.exe -w
> #cmdlinetest.rb
> pwd=`cd`
> puts "current directory:#{pwd}"
> user=`whoami`
> puts "you are logged in as:#{user}"
> exit if gets
>
>
> arose wrote:
> > What would I have to do to get Ruby to do the equivalent of typing cmd
> > in Windows Run and then interacting with the command prompt?
> >
> > I'm looking at some automation of running commands from the dos prompt.
> >

Martin DeMello

6/14/2006 8:26:00 PM

0

arose <arosel@ercot.com> wrote:
> Ok I half way understand what you are saying, I'm experimenting..
>
> I haven't used the ` character yet in Ruby
> Have time to explain it to me?

It's inherited from unix shells - `command` executes the command and
captures its STDOUT. Try a = `dir`; puts a

martin

Tim Hoolihan

6/14/2006 9:23:00 PM

0

Your welcome.

I see someone got to your first question. As for your original question
(automating of windows commands), you might want to look at expect.
It's a tool for automating cmdline interaction and there is a windows
port. If you really want to stay in ruby, there is a ruby library for
expect.

arose wrote:
> Ok I half way understand what you are saying, I'm experimenting..
>
> I haven't used the ` character yet in Ruby
> Have time to explain it to me?
>
> You have responded to a large number of my elementary questions,
> thanks.
>
>
>
> Tim Hoolihan wrote:
>> if you use commands that are native to the command line, the window will
>> come up.
>>
>> For instance, put the following in a .rb file and double click it:
>>
>> #!ruby.exe -w
>> #cmdlinetest.rb
>> pwd=`cd`
>> puts "current directory:#{pwd}"
>> user=`whoami`
>> puts "you are logged in as:#{user}"
>> exit if gets
>>
>>
>> arose wrote:
>>> What would I have to do to get Ruby to do the equivalent of typing cmd
>>> in Windows Run and then interacting with the command prompt?
>>>
>>> I'm looking at some automation of running commands from the dos prompt.
>>>
>

arose

6/14/2006 9:26:00 PM

0

cool, i didn't know that. Still seem to have some difficulties.

puts `dir` works

puts `dir c:\ruby` (or any other directory besides the one i'm in) does
not gives me file not found error; volume in drive c has no label.

why is this?



Martin DeMello wrote:
> arose <arosel@ercot.com> wrote:
> > Ok I half way understand what you are saying, I'm experimenting..
> >
> > I haven't used the ` character yet in Ruby
> > Have time to explain it to me?
>
> It's inherited from unix shells - `command` executes the command and
> captures its STDOUT. Try a = `dir`; puts a
>
> martin

Martin DeMello

6/15/2006 8:23:00 AM

0

arose <arosel@ercot.com> wrote:
> cool, i didn't know that. Still seem to have some difficulties.
>
> puts `dir` works
>
> puts `dir c:\ruby` (or any other directory besides the one i'm in) does
> not gives me file not found error; volume in drive c has no label.
>
> why is this?

not sure - might be a windows thing, or just an escaping problem. try it
with a forward slash instead of the backslash, or try c:\\ruby.

martin

Jeff Schwab

6/15/2006 11:25:00 AM

0

arose wrote:

> puts `dir` works
>
> puts `dir c:\ruby` (or any other directory besides the one i'm in) does
> not gives me file not found error; volume in drive c has no label.
>
> why is this?


Apparently, Ruby backquotes impose double-quote-style interpolation,
such that '\r' becomes a carriage return. I don't see this documented
anywhere, but I haven't checked the source...

irb(main):012:0> `echo #{"hello"}`
=> "hello\n"

arose

6/19/2006 6:23:00 PM

0

puts `dir "c:\\ruby"` works


Jeffrey Schwab wrote:
> arose wrote:
>
> > puts `dir` works
> >
> > puts `dir c:\ruby` (or any other directory besides the one i'm in) does
> > not gives me file not found error; volume in drive c has no label.
> >
> > why is this?
>
>
> Apparently, Ruby backquotes impose double-quote-style interpolation,
> such that '\r' becomes a carriage return. I don't see this documented
> anywhere, but I haven't checked the source...
>
> irb(main):012:0> `echo #{"hello"}`
> => "hello\n"

arose

6/19/2006 6:49:00 PM

0

ok this is way harder than i thought it would be. I thought a good
first program would be to write a ruby program that gets the
Class.method information through ri and made the html for me. I am
struggling with the cmd prompt.

for starters i tried this:
puts `ri "-Tf html String#gsub > gsub.html"`

I get an exec format error

tried this
puts `ri` and that returns the same error

puts `"ri -Tf html String#gsub > gsub.html"`
gives me a no such directory error.

any advice?


I can
arose wrote:
> puts `dir "c:\\ruby"` works
>
>
> Jeffrey Schwab wrote:
> > arose wrote:
> >
> > > puts `dir` works
> > >
> > > puts `dir c:\ruby` (or any other directory besides the one i'm in) does
> > > not gives me file not found error; volume in drive c has no label.
> > >
> > > why is this?
> >
> >
> > Apparently, Ruby backquotes impose double-quote-style interpolation,
> > such that '\r' becomes a carriage return. I don't see this documented
> > anywhere, but I haven't checked the source...
> >
> > irb(main):012:0> `echo #{"hello"}`
> > => "hello\n"

Tim Hoolihan

6/19/2006 8:07:00 PM

0

arose wrote:
> for starters i tried this:
> puts `ri "-Tf html String#gsub > gsub.html"`
>
You don't need to output the result (as there is no result since you're
wriging it to a file. And you don't need to double quote anything.

I tested and this works just fine:

`ri -Tf html String#gsub > gsub.html`

If you want to do this efficiently to a large amount of methods, try
something like this:

dummystring = String.new
dummystring.methods.each { |method|
`ri -Tf html String::#{method} > #{method}.html`
}