Description
The arg method doesn't track the total resulting command-line length and has no way of indicating to clients that the resulting command-line length would exceed the OS's underlying maximum length. This is fine for launching subprocesses with dozens of arguments, but renders it impossible to implement xargs or similar functionality.
Can I suggest a new method
fn try_add_arg<S: AsRef<OsStr>>(&mut self, arg: S) -> Option<S>
with documentation saying that it's only preferable to arg
when you're wanting multi-kilobyte command-lines?
try_add_arg
would keep track of the number of args already added, and if the number of args or the resulting length would exceed the OS limits, then it ignores the argument and returns it back to the client. Otherwise it acts like the normal arg
method and returns None.