[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

system (cmd) on windows

Rebhan, Gilbert

2/8/2007 3:52:00 PM


Hi,

two questions :

1.

system("T:/cvsnt/cvs.exe", "-d
:pserver:username@cvshost:d:/cvsrepos/test co Foobar")
doesn't work, whereas
system("T:/cvsnt/cvs.exe -d :pserver:username@cvshost:d:/cvsrepos/test
co Foobar")
works

all examples i found had system ("cmd", "args")
is that normal for some executables or is it a buggy behaviour from
cvs.exe ?


2.

my rubyscript lies under C:/cvs.rb
my cvsworkspace = T:/cvsworkspace

now i want to fire my cvs command out of the
cvsworkspace folder

in a windowshell i would do=
T:
cd workspace
T:/cvsnt/cvs.exe -d :pserver:username@cvshost:d:/cvsrepos/test co Foobar

how to emulate that with system(...)
i tried to ; separate it :

system("T:;cd workspace;T:/cvsnt/cvs.exe -d
:pserver:username@cvshost:d:/cvsrepos/test co Foobar")

but that doesn't work

Any ideas ?



Regards, Gilbert


1 Answer

Brian Candler

2/8/2007 4:01:00 PM

0

On Fri, Feb 09, 2007 at 12:51:35AM +0900, Rebhan, Gilbert wrote:
> 1.
>
> system("T:/cvsnt/cvs.exe", "-d
> :pserver:username@cvshost:d:/cvsrepos/test co Foobar")
> doesn't work, whereas
> system("T:/cvsnt/cvs.exe -d :pserver:username@cvshost:d:/cvsrepos/test
> co Foobar")
> works
>
> all examples i found had system ("cmd", "args")
> is that normal for some executables or is it a buggy behaviour from
> cvs.exe ?

No, you have to go entirely one way or the other. That is, either split out
all the arguments yourself:

system("T:/cvsnt/cvs.exe", "-d", ":pserver:username@cvshost:d:/cvsrepos/test", "co", "Foobar")

Or pass a single string, as in your second example, in which case the shell
will be used to split them.

Passing separate arguments is safer against certain forms of attack, and
makes it easy to pass arguments which themselves contains spaces or other
shell metacharacters.

> my rubyscript lies under C:/cvs.rb
> my cvsworkspace = T:/cvsworkspace
>
> now i want to fire my cvs command out of the
> cvsworkspace folder
>
> in a windowshell i would do=
> T:
> cd workspace
> T:/cvsnt/cvs.exe -d :pserver:username@cvshost:d:/cvsrepos/test co Foobar
>
> how to emulate that with system(...)
> i tried to ; separate it :
>
> system("T:;cd workspace;T:/cvsnt/cvs.exe -d
> :pserver:username@cvshost:d:/cvsrepos/test co Foobar")
>
> but that doesn't work

What error does it give? Perhaps you just need
system("T:;cd \\workspace; ..."

This won't work with the argument-split example given above. In that case
you could do it from Ruby, e.g.
Dir.chdir("...wherever...") do
system("...whatever..")
end

HTH,

Brian.