0

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.

15Step
  • 101
  • 4
  • Possibly a limit of the number of characters in line of text for the command from your OS. Check the string line length limits for Windows. Sorry, I am not Windows user, so cannot tell you that information. But this is a typical issue. At one time I think Windows had a limit of 256 characters. See https://learn.microsoft.com/en-us/windows/desktop/fileio/naming-a-file#maximum-path-length-limitation. It seems there is a way to use extended character lengths. – fmw42 Mar 14 '19 at 16:09
  • Thanks for the reply. I suspect this is also the case, as the code is otherwise robust. I will try to run it on Linux and see if this solves the problem – 15Step Mar 14 '19 at 16:18

1 Answers1

1

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.

Alberto L. Bonfiglio
  • 1,767
  • 23
  • 38
  • Thanks, the issue with breaking it down is that the `montage` function from ImageMagick takes one (long) argument detailing the paths of all the files to be montaged. The way around that is to use globbing (http://www.imagemagick.org/Usage/windows/#for_recursive) , but I'm not sure how to do this in combination with ruby. – 15Step Mar 14 '19 at 16:39
  • 1
    Maybe this could help? https://www.thoughtco.com/using-glob-with-directories-2907832 – Alberto L. Bonfiglio Mar 14 '19 at 22:06