[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

can I do windows shell scripting in ruby?

davy.bold

5/23/2007 12:30:00 PM

Hello,

I am totally new to ruby and interested in doing a backup job on
windows in ruby. Don't know if it is possible though!

I would need to get backups of Trac and Subversion with their
respective admin tools like svn-admin.exe.

So what the script should do is making a call like svn-admin arg1 arg2
etc.

How can I do this?

Thanks in advance

Davy

8 Answers

mrpink

5/23/2007 12:42:00 PM

0

davy.bold@googlemail.com wrote:
> Hello,
>
> I am totally new to ruby and interested in doing a backup job on
> windows in ruby. Don't know if it is possible though!
>
> I would need to get backups of Trac and Subversion with their
> respective admin tools like svn-admin.exe.
>
> So what the script should do is making a call like svn-admin arg1 arg2
> etc.
>
> How can I do this?
>
> Thanks in advance
>
> Davy
>

of course you can :) exec should be the right command for you:
http://www.rubycentral.com/book/ref_m_kernel.html#K...

--
greets

one must still have chaos in oneself to be able to
give birth to a dancing star

Jano Svitok

5/23/2007 12:47:00 PM

0

On 5/23/07, davy.bold@googlemail.com <davy.bold@googlemail.com> wrote:
> Hello,
>
> I am totally new to ruby and interested in doing a backup job on
> windows in ruby. Don't know if it is possible though!
>
> I would need to get backups of Trac and Subversion with their
> respective admin tools like svn-admin.exe.
>
> So what the script should do is making a call like svn-admin arg1 arg2
> etc.
>
> How can I do this?
>
> Thanks in advance

either
arg1 = "sdas"
arg2 = "sadada"
`svn-admin #{arg1} #{arg2}`

or replace the last line with
system('svn-admin', arg1, arg2)

Suraj Kurapati

5/24/2007 3:32:00 AM

0

Jano Svitok wrote:
> arg1 = "sdas"
> arg2 = "sadada"
> `svn-admin #{arg1} #{arg2}`

This only works if the arguments do not contain spaces (otherwise you
end up with more than 2 arguments!). In general, you should protect the
arguments with quotes using Object#inspect:

`svn-admin #{arg1.inspect} #{arg2.inspect}`

There are special cases when you don't need the particular way non-ASCII
characters are expressed (octal escape sequences), but this approach
works for most purposes.

--
Posted via http://www.ruby-....

Kyle Schmitt

5/24/2007 6:38:00 PM

0

Just a thought, there are versions of Perl, Rexx and Python that works
as a wsh (windows scripting host). Apparently it allows them some
special access to things, creating com objects etc. More or less a
direct hook into the local OS. More so than you get just by running a
different scripting language in windos. Perhaps some kind soul could
figure out how to do the same for ruby on windows?

I mean ruby on UNIX already has a close to, if not equal to, status as
sh and Perl for scripting, so getting it to work as a wsh script in
windows would be more along the lines of bringing the windows version
up to snuff.

Like I said, just a thought
--Kyle

Gordon Thiesfeld

5/24/2007 6:54:00 PM

0

Some kind soul already has. ActiveScriptRuby

http://www.geocities.co.jp/SiliconValley-PaloAlto/9251/ruby...

Gordon

Kyle Schmitt

5/24/2007 9:20:00 PM

0

Very cool. Alright then, that'd be the absolute _best_ way of doing
windows shell scripting in ruby: by using ruby as windows shell script
(wsh)!


Now to see if I can somehow convince Automated QA's Test-Complete to
use ActiveScriptRuby instead of vbscript or jscript ;)

--Kyle

Jenda Krynicky

5/25/2007 1:15:00 PM

0

Suraj Kurapati wrote:
> Jano Svitok wrote:
>> arg1 = "sdas"
>> arg2 = "sadada"
>> `svn-admin #{arg1} #{arg2}`
>
> This only works if the arguments do not contain spaces (otherwise you
> end up with more than 2 arguments!). In general, you should protect the
> arguments with quotes using Object#inspect:
>
> `svn-admin #{arg1.inspect} #{arg2.inspect}`
>
> There are special cases when you don't need the particular way non-ASCII
> characters are expressed (octal escape sequences), but this approach
> works for most purposes.

And why do you think the quoting rules of the shell/command processor
match, at least approximately the quoting rules of Ruby?

Imagine
arg1 = "some `cd /; rm -rf` sss"

now, what does .inspect do with this? It puts double quotes around the
string. FULLSTOP. What does a unix shell do with something enclosed in
backticks within a double quoted parameter? It EXECUTES the stuff as a
COMMAND and inserts the output into the doublequoted string. Try

echo "List is: `ls` and that's all"

in your shell!

Well, do you really want to have such a huge security hole in your
script? Do you? Imagine the arg1 came from the web! Besides the .inspect
only promises to return a "human-readable representation of obj".

If you do not need to capture the output of the command please use

system( command, arg1, arg2)

If you do, you need to be more carefull and use a method that was
designed to be safe. Or make sure and doublesure the arg1 and arg2 only
contains stuff that's safe. Please!

Jenda

--
Posted via http://www.ruby-....

Reid Thompson

5/25/2007 1:52:00 PM

0

Jenda Krynicky wrote:
> Suraj Kurapati wrote:
>> Jano Svitok wrote:
>>> arg1 = "sdas"
>>> arg2 = "sadada"
>>> `svn-admin #{arg1} #{arg2}`
>> This only works if the arguments do not contain spaces (otherwise you
>> end up with more than 2 arguments!). In general, you should protect the
>> arguments with quotes using Object#inspect:
>>
>> `svn-admin #{arg1.inspect} #{arg2.inspect}`
>>
>> There are special cases when you don't need the particular way non-ASCII
>> characters are expressed (octal escape sequences), but this approach
>> works for most purposes.
>
> And why do you think the quoting rules of the shell/command processor
> match, at least approximately the quoting rules of Ruby?
>
> Imagine
> arg1 = "some `cd /; rm -rf` sss"
>
> now, what does .inspect do with this? It puts double quotes around the
> string. FULLSTOP. What does a unix shell do with something enclosed in
> backticks within a double quoted parameter? It EXECUTES the stuff as a
> COMMAND and inserts the output into the doublequoted string. Try
>
> echo "List is: `ls` and that's all"
>
> in your shell!
>
> Well, do you really want to have such a huge security hole in your
> script? Do you? Imagine the arg1 came from the web! Besides the .inspect
> only promises to return a "human-readable representation of obj".
>
> If you do not need to capture the output of the command please use
>
> system( command, arg1, arg2)
>
> If you do, you need to be more carefull and use a method that was
> designed to be safe. Or make sure and doublesure the arg1 and arg2 only
> contains stuff that's safe. Please!
>
> Jenda
>
see popen.....