# System() doesn't work but %x does

**URL:** <https://www.ruby-forum.com/t/system-doesnt-work-but-x-does/112567>\
**Category:** Ruby\
**Created:** [August 21, 2007, 12:02am UTC](https://www.ruby-forum.com/t/system-doesnt-work-but-x-does/112567 "2007-08-21T00:02:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pmak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/5fc32e/32.png) [@pmak](https://www.ruby-forum.com/u/pmak)\
**Post date:** [August 21, 2007, 12:02am UTC](https://www.ruby-forum.com/t/system-doesnt-work-but-x-does/112567/1 "2007-08-21T00:02:08Z")

</div>

I’m trying to issue an “svn add” command from a script to add everything  
under the current folder to subversion.  
Command line works:

# svn add --force \*

%x / backticks work  
out = %x[svn add --force \*]

system() does not.  
system(‘svn’, ‘add’, ‘–force’, ‘_’) produces "svn: warning: '_’ not  
found"

I suspect there is some subtlety in regard to the expansion of the “\*”;  
is there any way of making it work with system()?

Thanks.

---

<div class="post-metadata">

**Author:** ![pmak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/5fc32e/32.png) [@pmak](https://www.ruby-forum.com/u/pmak)\
**Post date:** [August 21, 2007, 12:20am UTC](https://www.ruby-forum.com/t/system-doesnt-work-but-x-does/112567/2 "2007-08-21T00:20:38Z")

</div>

On 8/21/07, Philip M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> system(‘svn’, ‘add’, ‘–force’, ‘_') produces "svn: warning: '_’ not  
> found"
> 
> I suspect there is some subtlety in regard to the expansion of the “\*”;  
> is there any way of making it work with system()?

I guess ‘\*’ is handled by the shell. `` invokes the command via shell,  
while system does it directly (and you have to expand \* yourself).

So, there are two possibilities:

1. invoke /bin/sh (or whatever shell are you using) with arguments to  
call svn add…
2. expand it yourself (Dir.glob might be helpful)

NB: I’m curious: why do you insist on system()?

---

<div class="post-metadata">

**Author:** ![pmak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/5fc32e/32.png) [@pmak](https://www.ruby-forum.com/u/pmak)\
**Post date:** [August 21, 2007, 1:24am UTC](https://www.ruby-forum.com/t/system-doesnt-work-but-x-does/112567/3 "2007-08-21T01:24:42Z")

</div>

Hi,

At Tue, 21 Aug 2007 07:18:49 +0900,  
Jano S. wrote in [ruby-talk:265570]:

> > found"
> > 
> > I suspect there is some subtlety in regard to the expansion of the “\*”;  
> > is there any way of making it work with system()?
> 
> I guess ‘\*’ is handled by the shell. `` invokes the command via shell,  
> while system does it directly (and you have to expand \* yourself).

To be accurate, system with multiple arguments bypasses shell,  
while backticks and system with single string contains shell  
metacharacters invokes a shell.

> So, there are two possibilities:
> 
> 1. invoke /bin/sh (or whatever shell are you using) with arguments to  
> call svn add…
> 2. expand it yourself (Dir.glob might be helpful)

1. use single string argument.  
system(‘svn add --force \*’)

---

<div class="post-metadata">

**Author:** ![pmak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/5fc32e/32.png) [@pmak](https://www.ruby-forum.com/u/pmak)\
**Post date:** [August 21, 2007, 1:34am UTC](https://www.ruby-forum.com/t/system-doesnt-work-but-x-does/112567/4 "2007-08-21T01:34:11Z")

</div>

Jano S. wrote:

> NB: I’m curious: why do you insist on system()?

I’m using i386-cygwin and system() seemed to be better behaved when some  
of the tools I call are not cygwin based. (such as nant)
