Project

General

Profile

Actions

Bug #10336

closed

limit of number of arguments passed to system

Added by vpereira (Victor Pereira) over 9 years ago. Updated over 9 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux]
[ruby-core:65462]

Description

The following code snipped stops to work with argument bigger than 2274:

files_to_be_p_as_a =  Dir[File.join(".", '**', '*.c')]
files_to_be_p_as_a.size 
# => 43152
system("ls #{files_to_be_p_as_a}") 
# => nil
system("ls #{files_to_be_p_as_a[0..2273]}")
... # list of files
system("ls #{files_to_be_p_as_a[0..2274]}" 
# => nil

is there any limitation on Kernel system or is it something in my local environment?

Updated by vpereira (Victor Pereira) over 9 years ago

just adding the join() to my example.

system("ls #{files_to_be_p_as_a.join(' ')}") 
# => nil
system("ls #{files_to_be_p_as_a[0..2273].join(' ')}")
... # list of files
system("ls #{files_to_be_p_as_a[0..2274].join(' ')}") 

Updated by akr (Akira Tanaka) over 9 years ago

  • Status changed from Open to Rejected

POSIX systems can have a limitation on the size of arguments.

Use spawn() to raise the execption on the error of execve(2):

% ruby -v -retc -e 's = "true " + "a" * Etc.sysconf(Etc::SC_ARG_MAX); p s.length; Process.wait spawn(s)'
ruby 2.2.0dev (2014-10-05 trunk 47803) [x86_64-linux]
2097157
-e:1:in `spawn': Argument list too long - true (Errno::E2BIG)
	from -e:1:in `<main>'

Updated by vpereira (Victor Pereira) over 9 years ago

fine, however is the limitation imposed by my system (and tunable) or by ruby?

Updated by akr (Akira Tanaka) over 9 years ago

OS's limitation.
Not Ruby's limitation.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0