Reputation: 295
Problem:
In powershell 5.1 I run a command, myProgram
, and pass to its -itemsToProcess
flag a comma separated string list (of dynamic length), $commaSeparatedList
, as arguments. There are often too many characters, sometimes 125000 characters, or more, or less, in $commaSeparatedList
which can cause the error shown below.
$commaSeparatedList = 'file1,file2,file3,file4 ... fileX'
myProgram -itemsToProcess $commaSeparatedList
Question: How might I avoid the error? How might i split this into multiple calls such that the error is never thrown? The calls must be sequential too, not in parallel.
The pseudo code setup above works fine/succeeds when $commaSeparatedList
is short in character length , however if its too long it crashes/fails/errors:
"the filename or extension is too long"
For example, the dynamically generated $commaSeparatedList
has been 125k characters and could potentially be longer or shorter.
how might we detect and avoid the error? Perhaps somehow split it into multiple myProgram -itemsToProcess
calls to avoid the error? What would that look like?
Upvotes: 3
Views: 2552
Reputation: 295
Thanks for the comments, I split the input into smaller strings and made more calls
Upvotes: 1