system() doesn't work but %x does

P

Philip Mateescu

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

Jano Svitok

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()?

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()?
 
N

Nobuyoshi Nakada

Hi,

At Tue, 21 Aug 2007 07:18:49 +0900,
Jano Svitok wrote in [ruby-talk:265570]:
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()?

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)

3. use single string argument.
system('svn add --force *')
 
P

Philip Mateescu

Jano said:
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)
 

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

No members online now.

Forum statistics

Threads
474,264
Messages
2,571,315
Members
48,001
Latest member
Wesley9486

Latest Threads

Top