Error running 'montage' function in ImageMagick 'too many arguments'?

252 Views Asked by At

I'm trying to run the montage function in ImageMagick with a large number of arguments (264) directly through a ruby script. Here is the line that calls the function:

montage -mode concatenate -tile #{x_tiles}x#{y_tiles} #{tempfiles.map{|t| t.path}.join(' ')} #{final_filename}.jpg

This works for a smaller number of arguments (e.g. 10), but when I try to run this with a larger amount (230~) I get the following error:

Argument list too long {list of all the arguments} (Errno: :E2BIG).

I'm using Windows so I tried both PowerShell and CMD, getting the same error.

Is there a way to overcome this in editing the command in ruby or otherwise (e.g. by globbing)? I tried to change the file ending as mentioned here but couldn't get the syntax right.

1

There are 1 best solutions below

2
On

One thing to do is to check the length of the command string before running it. If it's too long, for the system you're in, you may need to break it down into smaller chunks.

Without knowing the length you're running, according to Microsoft Support

On computers running Microsoft Windows XP or later, the maximum length of the string that you can use at the command prompt is 8191 characters. On computers running Microsoft Windows 2000 or Windows NT 4.0, the maximum length of the string that you can use at the command prompt is 2047 characters.

Also Linux has a limitation as well on the length of the command. See "Argument list too long": Beyond Arguments and Limitations

On Linux you could recompile the kernel to increase the page size but on windows you have no such option.