Is there a limit to content stored in -ErrorVariable?

This topic contains 5 replies, has 3 voices, and was last updated by  Arie H 2 years, 1 month ago.

  • Author
  • #38475

    Ryan Young

    Hello! I'm trying to use the '-ErrorVariable' to populate a variable with a ton of errors, and then use those errors as a source for other commands (parsed and then fed into a command). The command I'm trying to run is:

     Invoke-Expression "p4 -u $p4user -p $sbport verify -q -z //SandboxView/...#=head" -ErrorVariable MissedTransfers 

    The question I have: Is there a limited size of content that this variable will store? I know that the built in variable in powershell $error will only store something like 500 lines of error before over-writing. I need my "$MissedTransfers" variable to be limitless. I can't seem to find any information online about this.

  • #38477

    Richard Siddaway

    The number of errors that can be stored in $error before it starts to overwrite is controlled by $maximumErrorCount whose default value is 256. Its maximum value is 32768.

    is you expression to be run once or many times? If it runs many times you'll overwrite the contents of your error variable

    Also think about the number of errors you may get – eventually you'll run out of memory

  • #38479

    Ryan Young

    Hi Richard and thanks for your quick answer. So yes it will run once, and during the running will populate hundreds or thousands of errors. I will then take the error output and feed it to another command that will go and 'fetch' the files that don't exist on the local disk. Basically, I'm validating if the file exists against a database, and if it doesn't then talk to another server and go get the file. To do that I'm parsing the error output for the filename/path expected.

    As for running out of memory, while that's something to watch out for it's not a major concern because we're running this in a vmware environment and can easily up the memory of the server.

    So I understand that $error can only contain 256 lines. Does that same limitation apply to error variables I define myself via invoke-expression -errorvariable?

  • #38480

    Arie H

    I don't think you can tell perforce command line to split its results or errors, not a perforce expert, so maybe help on their forums would aid you as well, but because its a command line, I would pipe I into a file, add '> c:\output.txt' without the parentheses as part of the expression and then have PS parse the file. That way you're not limiting yourself in any way.

  • #38481

    Ryan Young

    Hi Arie,

    I am doing essentially what you are saying, but rather than writing to file I'm populating an error variable. I can then split on the variable because the variable is a psobject.

  • #38482

    Arie H

    yes but youre using a "limited" way compared to a non limited way

You must be logged in to reply to this topic.