question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

STDOUT/STDIN buffer size error when passing arguments into Windows PowerShell

See original GitHub issue

This issue is partially an issue of Windows PowerShell and PowerShell.

When I try pass a PSCustomObject loaded from JSON from PowerShell into Windows PowerShell, it will fail once JSON pass a certain size level.

PowerShell 7.1.1 and Windows PowerShell throw different errors and passing through of PSCustomObject argument doesn’t work from properly. It depends on the argument size or complexity, see this screenshot.

2021-02-12 150531 l5lxRrDMSR

The problem disappears when I remove any two subkeys from root\WebApp in the configuration JSON.

Steps to reproduce

For a minimal, reproducible example, see this comment. When I debug the PS run, it pointed me to STDOUT/STDIN buffer size too.

$configuration = Get-Content .\configuration.json | ConvertFrom-Json
$block = {param([pscustomobject]$inputArgument) $PSVersionTable; Write-Host ('Test ' + $inputArgument.AxisUser.Name)}
powershell -nologo -noprofile $block -Args $configuration

Expected behavior

Windows PowerShell

Name                           Value
----                           -----
PSVersion                      5.1.18362.1171
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.18362.1171
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
Test String from json

PowerShell 7.1.1

Name                           Value
----                           -----
PSVersion                      5.1.18362.1171
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.18362.1171
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
Test String from json

Actual behavior

Windows PowerShell

Program 'powershell.exe' failed to run: Filename or Extension too longAt line:1
char:1
+ powershell -nologo -noprofile $block -Args $configuration
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.
At line:1 char:1
+ powershell -nologo -noprofile $block -Args $configuration
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
    + FullyQualifiedErrorId : NativeCommandFailed

PowerShell 7.1.1

ResourceUnavailable: Program 'powershell.exe' failed to run: The Process object must have the UseShellExecute property set to false in order to use environment variables.At line:1 char:1
+ powershell -nologo -noprofile $block -Args $configuration
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.

Environment data

Name                           Value
----                           -----
PSVersion                      7.1.1
PSEdition                      Core
GitCommitId                    7.1.1
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Configuration JSON

{
    "SupportedPSVersion": "7.1.0",
    "Localhost": true,
    "SourceCodeLocalPath": "%USERPROFILE%\\source\\CompanyName\\ProductName\\",
    "AzureDevOpsUser": {
        "Name": "",
        "Password": ""
    },
    "VPNUserName": "John.Doe",
    "ProductNameUser": {
        "Name": "String from json",
        "FullName": "ProductName DEV user",
        "Password": "123456",
        "Group": "Department"
    },
    "NetworkHost": "0.0.0.0",
    "AppPool": {
        "Name": "ProductName"
    },
    "Website": [
        {
            "Name": "ProductNameWeb",
            "Port": 1810,
            "ApplicationPool": "ProductName",
            "BindingInformation": "*:1810:",
            "Id": 2,
            "PhysicalPath": "%SystemDrive%\\inetpub\\wwwroot",
            "SelfSignedCertificatePassword": "WithGreatPowerComesGreatResponsibility"
        },
        {
            "Name": "ProductNameApp",
            "Port": 1985,
            "ApplicationPool": "ProductName",
            "BindingInformation": "*:1985:",
            "Id": 3,
            "PhysicalPath": "%SystemDrive%\\inetpub\\wwwroot"
        }
    ],
    "FrontendWebsiteId": 2,
    "BackendWebsiteId": 3,
    "FrontendEndpointToSubstitude": "ProductNamev2devweb1.ProductNamegraphics.tv",
    "BackendEndpointToSubstitude": "ProductNamev2devapp1.ProductNamegraphics.tv",
    "WebApp": {
        "Portal": {
            "FilePathToConfig": "%USERPROFILE%\\source\\CompanyName\\ProductName\\portal\\CompanyName.Portal.Web\\Root.Web.Release-Dev.config",
            "TargetAbsolutePathToConfig": "%SystemDrive%\\inetpub\\wwwroot\\Web.config",
            "ProjectsToPublish": [
                {
                    "RelativeProjectPath": "portal\\CompanyName.Portal.Web\\CompanyName.Portal.Web.csproj",
                    "RelativePublishProfilePath": "portal\\CompanyName.Portal.Web\\Properties\\PublishProfiles\\FolderProfile.pubxml"
                },
                {
                    "RelativeProjectPath": "portal\\CompanyName.Portal.API\\CompanyName.Portal.API.csproj",
                    "RelativePublishProfilePath": "portal\\CompanyName.Portal.API\\Properties\\PublishProfiles\\FolderProfile.pubxml"
                },
                {
                    "RelativeProjectPath": "portal\\CompanyName.Portal.Application.WebService\\CompanyName.Portal.Application.WebService.csproj",
                    "RelativePublishProfilePath": "portal\\CompanyName.Portal.Application.WebService\\Properties\\PublishProfiles\\FolderProfile.pubxml"
                }
            ],
            "SymbolicLinkToCreate": [],
            "AppToCreateOnFrontendWebsite": [
                {
                    "Name": "Portal",
                    "PhysicalPath": "%SystemDrive%\\inetpub\\wwwroot\\Portal"
                },
                {
                    "Name": "PortalApi",
                    "PhysicalPath": "%SystemDrive%\\inetpub\\wwwroot\\PortalApi"
                }
            ],
            "AppToCreateOnBackendWebsite": [
                {
                    "Name": "Portal",
                    "PhysicalPath": "%SystemDrive%\\inetpub\\wwwroot\\CompanyName.Portal.Application.WebService"
                }
            ],
            "HomePageFiles": {
                "TargetWebApplication": "Portal",
                "Name": "HomePageFiles",
                "PhysicalPath": "\\\\0.0.0.0\\pogo\\ProductNamev2\\dev\\Portal\\HomePageFiles"
            }
        },
        "Track": {
            "ProjectsToPublish": [
                {
                    "RelativeProjectPath": "track\\CompanyName.Track.Web\\CompanyName.Track.Web.csproj",
                    "RelativePublishProfilePath": "track\\CompanyName.Track.Web\\Properties\\PublishProfiles\\FolderProfile.pubxml"
                },
                {
                    "RelativeProjectPath": "track\\CompanyName.Track.Api\\CompanyName.Track.Api.csproj",
                    "RelativePublishProfilePath": "track\\CompanyName.Track.Api\\Properties\\PublishProfiles\\FolderProfile.pubxml"
                },
                {
                    "RelativeProjectPath": "track\\CompanyName.Track.WebService\\CompanyName.Track.WebService.csproj",
                    "RelativePublishProfilePath": "track\\CompanyName.Track.WebService\\Properties\\PublishProfiles\\FolderProfile.pubxml"
                },
                {
                    "RelativeProjectPath": "track\\CompanyName.Track.ConfigurationDomain\\CompanyName.Track.ConfigurationDomain.csproj",
                    "RelativePublishProfilePath": "track\\CompanyName.Track.ConfigurationDomain\\Properties\\PublishProfiles\\FolderProfile.pubxml"
                }
            ],
            "SymbolicLinkToCreate": [
                {
                    "RelativePublishProfilePath": "track\\CompanyName.Track.Web\\Properties\\PublishProfiles\\FolderProfile.pubxml",
                    "TargetRelativePath": "bin\\Shared",
                    "SourcePath": "%SystemDrive%\\inetpub\\wwwroot\\Portal\\bin"
                },
                {
                    "RelativePublishProfilePath": "track\\CompanyName.Track.Web\\Properties\\PublishProfiles\\FolderProfile.pubxml",
                    "TargetRelativePath": "Shared",
                    "SourcePath": "%SystemDrive%\\inetpub\\wwwroot\\Portal\\Shared"
                }
            ],
            "AppToCreateOnFrontendWebsite": [
                {
                    "Name": "Track",
                    "PhysicalPath": "%SystemDrive%\\inetpub\\wwwroot\\Track"
                },
                {
                    "Name": "TrackApi",
                    "PhysicalPath": "%SystemDrive%\\inetpub\\wwwroot\\CompanyName.Track.Api"
                },
                {
                    "Name": "ConfigurationDomain",
                    "PhysicalPath": "%SystemDrive%\\inetpub\\wwwroot\\CompanyName.Track.ConfigurationDomain"
                }
            ],
            "AppToCreateOnBackendWebsite": [
                {
                    "Name": "Track",
                    "PhysicalPath": "%SystemDrive%\\inetpub\\wwwroot\\CompanyName.Track.WebService"
                }
            ],
            "Cache": {
                "LocalFolderPath": "%SystemDrive%\\inetpub\\wwwroot\\TrackCache",
                "Name": "TrackCache\\Cache",
                "PhysicalPath": "\\\\1.1.1.1\\pogo\\ProductNamev2\\dev\\track"
            },
            "VueJS": {
                "RelativeSourcePath": "track\\CompanyName.Track.Web\\",
                "RelativeBuildPath": "track\\CompanyName.Track.Web\\src\\build",
                "Destination": "%SystemDrive%\\inetpub\\wwwroot\\Track\\src\\"
            }
        },
        "ProductNameAPI": {
            "ProjectsToPublish": [
                {
                    "RelativeProjectPath": "ProductNameapi\\ProductNameAPI\\ProductNameAPI.csproj",
                    "RelativePublishProfilePath": "ProductNameapi\\ProductNameAPI\\Properties\\PublishProfiles\\FolderProfile.pubxml"
                }
            ],
            "SymbolicLinkToCreate": [],
            "AppToCreateOnFrontendWebsite": [
                {
                    "Name": "ProductNameApi",
                    "PhysicalPath": "%SystemDrive%\\inetpub\\wwwroot\\ProductNameApi"
                }
            ],
            "AppToCreateOnBackendWebsite": []
        },
        "Compose": {
            "ProjectsToPublish": [
                {
                    "RelativeProjectPath": "compose\\CompanyName.Compose.Web\\CompanyName.Compose.Web.csproj",
                    "RelativePublishProfilePath": "compose\\CompanyName.Compose.Web\\Properties\\PublishProfiles\\FolderProfile.pubxml"
                }
            ],
            "SymbolicLinkToCreate": [
                {
                    "RelativePublishProfilePath": "compose\\CompanyName.Compose.Web\\Properties\\PublishProfiles\\FolderProfile.pubxml",
                    "TargetRelativePath": "bin\\Shared",
                    "SourcePath": "%SystemDrive%\\inetpub\\wwwroot\\Portal\\bin"
                }
            ],
            "AppToCreateOnFrontendWebsite": [
                {
                    "Name": "Compose",
                    "PhysicalPath": "%SystemDrive%\\inetpub\\wwwroot\\Compose"
                }
            ],
            "AppToCreateOnBackendWebsite": []
        },
        "Charts": {
            "ProjectsToPublish": [
                {
                    "RelativeProjectPath": "charts\\CompanyName.Charts.Web\\CompanyName.Charts.Web.csproj",
                    "RelativePublishProfilePath": "charts\\CompanyName.Charts.Web\\Properties\\PublishProfiles\\FolderProfile.pubxml"
                }
            ],
            "SymbolicLinkToCreate": [
                {
                    "RelativePublishProfilePath": "charts\\CompanyName.Charts.Web\\Properties\\PublishProfiles\\FolderProfile.pubxml",
                    "TargetRelativePath": "bin\\Shared",
                    "SourcePath": "%SystemDrive%\\inetpub\\wwwroot\\Portal\\bin"
                }
            ],
            "AppToCreateOnFrontendWebsite": [
                {
                    "Name": "Charts",
                    "PhysicalPath": "%SystemDrive%\\inetpub\\wwwroot\\Charts"
                }
            ],
            "AppToCreateOnBackendWebsite": [],
            "VueJS": {
                "RelativeSourcePath": "charts\\CompanyName.Charts.Web\\",
                "RelativeBuildPath": "charts\\CompanyName.Charts.Web\\src\\build",
                "Destination": "%SystemDrive%\\inetpub\\wwwroot\\Charts\\src\\"
            }
        },
        "Order": {
            "ProjectsToPublish": [
                {
                    "RelativeProjectPath": "order\\CompanyName.Order.Web\\CompanyName.Order.Web.csproj",
                    "RelativePublishProfilePath": "order\\CompanyName.Order.Web\\Properties\\PublishProfiles\\FolderProfile.pubxml"
                }
            ],
            "SymbolicLinkToCreate": [
                {
                    "RelativePublishProfilePath": "order\\CompanyName.Order.Web\\Properties\\PublishProfiles\\FolderProfile.pubxml",
                    "TargetRelativePath": "bin\\Shared",
                    "SourcePath": "%SystemDrive%\\inetpub\\wwwroot\\Portal\\bin"
                }
            ],
            "AppToCreateOnFrontendWebsite": [
                {
                    "Name": "Order",
                    "PhysicalPath": "%SystemDrive%\\inetpub\\wwwroot\\Order"
                }
            ],
            "AppToCreateOnBackendWebsite": [],
            "MediaFormatImages": {
                "LocalFolderPath": "%SystemDrive%\\inetpub\\wwwroot\\MediaFormatImages",
                "Name": "MediaFormatImages",
                "PhysicalPath": "\\\\1.1.1.1\\pogo\\ProductNamev2\\dev\\Order\\MediaFormatImages"
            }
        },
        "Typefaces": {
            "ProjectsToPublish": [
                {
                    "RelativeProjectPath": "typefaces\\CompanyName.Typefaces.Web\\CompanyName.Typefaces.Web.csproj",
                    "RelativePublishProfilePath": "typefaces\\CompanyName.Typefaces.Web\\Properties\\PublishProfiles\\FolderProfile.pubxml"
                }
            ],
            "SymbolicLinkToCreate": [
                {
                    "RelativePublishProfilePath": "typefaces\\CompanyName.Typefaces.Web\\Properties\\PublishProfiles\\FolderProfile.pubxml",
                    "TargetRelativePath": "bin\\Shared",
                    "SourcePath": "%SystemDrive%\\inetpub\\wwwroot\\Portal\\bin"
                }
            ],
            "AppToCreateOnFrontendWebsite": [
                {
                    "Name": "Typefaces",
                    "PhysicalPath": "%SystemDrive%\\inetpub\\wwwroot\\Typefaces"
                }
            ],
            "AppToCreateOnBackendWebsite": []
        },
        "Transport": {
            "ProjectsToPublish": [
                {
                    "RelativeProjectPath": "transport\\CompanyName.Transport.Web\\CompanyName.Transport.Web.csproj",
                    "RelativePublishProfilePath": "transport\\CompanyName.Transport.Web\\Properties\\PublishProfiles\\FolderProfile.pubxml"
                }
            ],
            "SymbolicLinkToCreate": [
                {
                    "RelativePublishProfilePath": "transport\\CompanyName.Transport.Web\\Properties\\PublishProfiles\\FolderProfile.pubxml",
                    "TargetRelativePath": "bin\\Shared",
                    "SourcePath": "%SystemDrive%\\inetpub\\wwwroot\\Portal\\bin"
                }
            ],
            "AppToCreateOnFrontendWebsite": [
                {
                    "Name": "Transport",
                    "PhysicalPath": "%SystemDrive%\\inetpub\\wwwroot\\Transport"
                }
            ],
            "AppToCreateOnBackendWebsite": []
        }
    },
    "NuGet": {
        "RestoreProjectForAzureCredentialManager": "%USERPROFILE%\\source\\CompanyName\\ProductName\\portal\\CompanyName.Portal.Web\\CompanyName.Portal.Web.csproj"
    }
}

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
iRon7commented, Mar 11, 2021

Agree, I guess it has something to do with the STDOUT/STDIN buffer size and leave it to the PowerShell guys to answer…

A Minimal, Reproducible Example of this issue would be:

powershell {''} -Args ('x' * 100000)

Results in an error:

ResourceUnavailable: Program 'powershell.exe' failed to run: The Process object must have the UseShellExecute property set to false in order to use environment variables.At line:1 char:1

(Where the error doesn’t appear with smaller strings, e.g.: powershell {''} -Args ('x' * 10000)

1reaction
iRon7commented, Feb 13, 2021

Unlike the CMD prompt, PowerShell doesn’t automatically Expand Environmental Variables which leaves an invalid json file. This means that you will need to explicitly expand the $configuration file before passing it as an argument.

In other works, your long/complex json configuration works fine for me when it is first expanded:

$configuration = Get-Content .\configuration.json | ConvertFrom-Json
$configuration = [System.Environment]::ExpandEnvironmentVariables($configuration)
$block = {param([pscustomobject]$inputArgument) $PSVersionTable; Write-Host ('Test ' + $inputArgument.AxisUser.Name)}
powershell -nologo -noprofile $block -Args $configuration
Read more comments on GitHub >

github_iconTop Results From Across the Web

Powershell StandardOutput buffer too small for external ...
What I'm attempting to do is read in output from an external command, specifically steamcmd, using powershell start-process and System.
Read more >
about Functions Advanced Parameters - PowerShell
PowerShell generates an error if the length of a value specified for a parameter or a variable is outside of the range.
Read more >
Test-Connection (Microsoft.PowerShell.Management)
TestConnectionCommand+TraceStatus] objects, are output to the Success output stream. Parameters. -BufferSize. Specifies the size, in bytes, of the buffer sent ...
Read more >
Write-Output (Microsoft.PowerShell.Utility)
Writes the specified objects to the pipeline. If Write-Output is the last command in the pipeline, the objects are displayed in the console....
Read more >
Validating Parameter Input - PowerShell
PowerShell can validate the length, the range, and the pattern of the characters of the argument. It can validate the number of arguments...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found