can I do windows shell scripting in ruby?

D

davy.bold

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
 
A

anansi

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#Kernel.exec
 
J

Jano Svitok

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)
 
S

Suraj Kurapati

Jano said:
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.
 
K

Kyle Schmitt

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
 
K

Kyle Schmitt

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
 
J

Jenda Krynicky

Suraj said:
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
 
R

Reid Thompson

Jenda said:
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.....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,260
Messages
2,571,301
Members
47,944
Latest member
LillianPra

Latest Threads

Top