Powershell 5.1 - the filename or extension is too long. How to split 1 command with dynamic arguments into more sequential calls?

1.9k views Asked by At

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" 

enter image description here

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?

1

There are 1 answers

0
Peter Noges On

Thanks for the comments, I split the input into smaller strings and made more calls