# System (cmd) on windows

**URL:** <https://www.ruby-forum.com/t/system-cmd-on-windows/84911>\
**Category:** Ruby\
**Created:** [February 8, 2007, 4:52pm UTC](https://www.ruby-forum.com/t/system-cmd-on-windows/84911 "2007-02-08T16:52:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RebhanS\_Gilbert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7feea3/32.png) [@RebhanS\_Gilbert](https://www.ruby-forum.com/u/RebhanS_Gilbert)\
**Post date:** [February 8, 2007, 4:52pm UTC](https://www.ruby-forum.com/t/system-cmd-on-windows/84911/1 "2007-02-08T16:52:34Z")

</div>

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 ?

1. 

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

---

<div class="post-metadata">

**Author:** ![RebhanS\_Gilbert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7feea3/32.png) [@RebhanS\_Gilbert](https://www.ruby-forum.com/u/RebhanS_Gilbert)\
**Post date:** [February 8, 2007, 5:02pm UTC](https://www.ruby-forum.com/t/system-cmd-on-windows/84911/2 "2007-02-08T17:02:35Z")

</div>

On Fri, Feb 09, 2007 at 12:51:35AM +0900, Rebhan, Gilbert wrote:

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

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