Can I do windows shell scripting in ruby?

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 :slight_smile: exec should be the right command for you: http://www.rubycentral.com/book/ref_m_kernel.html#Kernel.exec

···

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

--
greets

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

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

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

···

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

hey, that is awesome how fast the response came. This encourages me to
learn ruby as scripting language as I need to know about one!
So it worked out!

···

On 23 Mai, 14:46, "Jano Svitok" <jan.svi...@gmail.com> wrote:

On 5/23/07, davy.b...@googlemail.com <davy.b...@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)

hey, that is awesome how fast the response came. This encourages me to
learn ruby as scripting language as I need to know about one!
So it worked out!

By the way, where can I find posting rules for this newsgroup?

thanks

Daniel

···

On 23 Mai, 14:46, "Jano Svitok" <jan.svi...@gmail.com> wrote:

On 5/23/07, davy.b...@googlemail.com <davy.b...@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)

hey, that is awesome how fast the response came. This encourages me to
learn ruby as scripting language as I need to know about one!
So it worked out!

By the way, where can I find posting rules for this newsgroup?

thanks

Daniel

···

On 23 Mai, 14:46, "Jano Svitok" <jan.svi...@gmail.com> wrote:

On 5/23/07, davy.b...@googlemail.com <davy.b...@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)

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-forum.com/\.

there are no rules here but if you break one they are spamming your threads, just take a look at Ari Brown's post...

···

davy.bold@googlemail.com wrote:

By the way, where can I find posting rules for this newsgroup?

thanks

Daniel

--
greets

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

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

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-forum.com/\.

By the way, where can I find posting rules for this newsgroup?

there are no rules here but if you break one they are spamming your
threads, just take a look at Ari Brown's post...

Posting guidelines can be found here:
http://hypermetrics.com/rubyhacker/clrFAQ.html#tag22

best regards,
Helge

Some kind soul already has. ActiveScriptRuby

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

Gordon

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.....

On that subject -- I notice that the ruby-talk posting guidelines refer
to USENET etiquette, but don't cover all the major USENET etiquette
rules. That being the case, it seems to me that it might make sense to
either change the ruby-talk guidelines so they incorporate the rest of
the common USENET etiquette guidelines or eliminate the reference to
USENET etiquette (or "netiquette", if you prefer).

In fact, I suspect this reference to USENET etiquette with a lack of
duplication of all relevant rules of USENET etiquette in the guidelines
is the source of the issue with signature length. According to USENET
tradition, sig blocks should not be more than four lines at eighty
columns of signature, as anything longer runs a significant risk of
being longer than the main text of a post and dominating the email while
anything more than eighty columns runs the risk of running off the right
side of someone's screen (or wrapping strangely so that text is made
"funny-looking" and more difficult to read quickly).

As far as I've been able to determine over the last decade or so, the
best sources of netiquette (which is, regardless of actual transmission
method, usually just a derivative of USENET common decency traditions)
include:

  RFC 1855:
    RFC 1855 - Netiquette Guidelines

  USENET and Mailing List posting netiquette
    USENET and Mailing List posting netiquette

  Best Online Quoting Practices
    http://wiki.ursine.ca/Best_Online_Quoting_Practices

  Zen and the Art of the Internet: ``Usenet Netiquette''
    Zen and the Art of the Internet - Usenet News

  Lost in Usenet - References (at faqs.org)
    Lost in Usenet

Only the "Best Online Quoting Practices" doesn't mention the practical,
polite limit of four lines on signature blocks, to continue with the
signature length limit, and in that case only because the question of
signature formatting is off-topic for that document. Despite this, the
ruby-talk (aka comp.lang.ruby, aka Ruby forum) etiquette guidelines do
not mention that at all, while only vaguely referencing USENET
etiquette without links. That being the case, I'm not terribly
surprised that "anansi" has the impression that undocumented rules are
strictly enforced. Again, I think either the reference to USENET
etiquette guidelines needs to be eliminated (or made to appear less
directly relevant) or augmented with more complete inclusion of the
expected rules of etiquette and/or links if we wish to avoid such
confusion in the future.

···

On Thu, May 24, 2007 at 12:36:44AM +0900, Helge A. Gudmundsen wrote:

>> By the way, where can I find posting rules for this newsgroup?

>there are no rules here but if you break one they are spamming your
>threads, just take a look at Ari Brown's post...

Posting guidelines can be found here:
http://hypermetrics.com/rubyhacker/clrFAQ.html#tag22

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
Larry Wall: "A script is what you give the actors. A program is what you
give the audience."

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 :wink:

--Kyle