Skip to content

Experimental feature PSNativeCommandArgumentPassing breaks invocation of WSH scripts (VBScript, JScript) with arguments #15289

Closed

Description

Note: The common denominator here is invocation of scripts implicitly via WSH (Windows Scripting Host, cscript.exe and wscript.exe), which therefore equally affects VBScript and JScript script files.

Steps to reproduce

On Windows, assuming that experimental feature PSNativeCommandArgumentPassing is enabled (and $PSNativeCommandArgumentPassing is set to 'Standard'):

# Switch to a temporary directory.
Push-Location -ea Stop ($tmpDir = (New-Item -Type Directory -Force (Join-Path Temp:/ $PID)).FullName)

try {

  'Wscript.Echo("hi")' > t.vbs
  { ./t.vbs foo  } | Should -Not -Throw

} finally {
  # Clean up.
  Pop-Location; Remove-Item $tmpDir -Recurse
}

Expected behavior

The test should pass.

Actual behavior

The test fails with the following error:

Expected no exception to be thrown, but an exception "
Program 't.vbs' failed to run:  Only one of Arguments or ArgumentList may be used. ...
" was thrown.

In versions prior to PowerShell Core 7.2.0-preview.5 (and with $PSNativeCommandArgumentPassing= 'Legacy'), the test passes.

Environment data

PowerShell Core 7.2.0-preview.5

Activity

  1. SteveL-MSFT commented on Apr 22, 2021

    @SteveL-MSFT
    Member

    Michael Klement (@mklement0) good find. Here's the stack trace:

    PS> gerr
    
    Exception             :
        Type           : System.Management.Automation.ApplicationFailedException
        ErrorRecord    :
            Exception             :
                Type    : System.Management.Automation.ParentContainsErrorRecordException
                Message : Program 't.vbs' failed to run: Only one of Arguments or ArgumentList may be used.At line:1 char:1
                          + .\t.vbs foo
                          + ~~~~~~~~~~~.
                HResult : -2146233087
            CategoryInfo          : ResourceUnavailable: (:) [], ParentContainsErrorRecordException
            FullyQualifiedErrorId : NativeCommandFailed
            InvocationInfo        :
                ScriptLineNumber : 1
                OffsetInLine     : 1
                HistoryId        : -1
                Line             : .\t.vbs foo
                PositionMessage  : At line:1 char:1
                                   + .\t.vbs foo
                                   + ~~~~~~~~~~~
                CommandOrigin    : Internal
            ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
        TargetSite     :
            Name          : InitNativeProcess
            DeclaringType : System.Management.Automation.NativeCommandProcessor, System.Management.Automation,
    Version=7.2.0.5, Culture=neutral, PublicKeyToken=31bf3856ad364e35
            MemberType    : Method
            Module        : System.Management.Automation.dll
        StackTrace     :
       at System.Management.Automation.NativeCommandProcessor.InitNativeProcess()
       at System.Management.Automation.NativeCommandProcessor.Prepare(IDictionary psDefaultParameterValues)
       at System.Management.Automation.CommandProcessorBase.DoPrepare(IDictionary psDefaultParameterValues)
       at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean incomingStream)
       at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
    --- End of stack trace from previous location ---
       at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
       at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput,
    CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections,
    FunctionContext funcContext)
       at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
       at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
        Message        : Program 't.vbs' failed to run: Only one of Arguments or ArgumentList may be used.At line:1 char:1
                         + .\t.vbs foo
                         + ~~~~~~~~~~~.
        Data           : System.Collections.ListDictionaryInternal
        InnerException :
            Type       : System.InvalidOperationException
            TargetSite :
                Name          : Start
                DeclaringType : System.Diagnostics.Process
                MemberType    : Method
                Module        : System.Diagnostics.Process.dll
            StackTrace :
       at System.Diagnostics.Process.Start()
       at System.Management.Automation.NativeCommandProcessor.InitNativeProcess()
            Message    : Only one of Arguments or ArgumentList may be used.
            Source     : System.Diagnostics.Process
            HResult    : -2146233079
        Source         : System.Management.Automation
        HResult        : -2146233087
    CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
    FullyQualifiedErrorId : NativeCommandFailed
    InvocationInfo        :
        ScriptLineNumber : 1
        OffsetInLine     : 1
        HistoryId        : -1
        Line             : .\t.vbs foo
        PositionMessage  : At line:1 char:1
                           + .\t.vbs foo
                           + ~~~~~~~~~~~
        CommandOrigin    : Internal
    ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
  2. changed the title [-]Experimental feature PSNativeCommandArgumentPassing breaks invocation of VBScripts with arguments[/-] [+]Experimental feature PSNativeCommandArgumentPassing breaks invocation of WSH scripts (VBScript, JScript) with arguments[/+] on Apr 22, 2021
  3. daxian-dbw commented on May 3, 2021

    @daxian-dbw
    Member
  4. End-of-Eternity commented on May 25, 2021

    @End-of-Eternity

    I've also encountered this issue when running python scripts directly.
    For example test.py someargs will throw the error

    ResourceUnavailable: Program 'test.py' failed to run: Only one of Arguments or ArgumentList may be used.At line:1 char:1

    Stack trace:

    Exception             :
        Type           : System.Management.Automation.ApplicationFailedException
        ErrorRecord    :
            Exception             :
                Type    : System.Management.Automation.ParentContainsErrorRecordException
                Message : Program 'test.py' failed to run: Only one of Arguments or ArgumentList may be used.At line:1 char:1
                          + ./test.py someargs
                          + ~~~~~~~~~~~~~~~~~~.
                HResult : -2146233087
            CategoryInfo          : ResourceUnavailable: (:) [], ParentContainsErrorRecordException
            FullyQualifiedErrorId : NativeCommandFailed
            InvocationInfo        :
                ScriptLineNumber : 1
                OffsetInLine     : 1
                HistoryId        : -1
                Line             : ./test.py someargs
                PositionMessage  : At line:1 char:1
                                   + ./test.py someargs
                                   + ~~~~~~~~~~~~~~~~~~
                CommandOrigin    : Internal
            ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
        TargetSite     :
            Name          : InitNativeProcess
            DeclaringType : System.Management.Automation.NativeCommandProcessor, System.Management.Automation, Version=7.2.0.5, Culture=neutral, PublicKeyToken=31bf3856ad364e35
            MemberType    : Method
            Module        : System.Management.Automation.dll
        StackTrace     :
       at System.Management.Automation.NativeCommandProcessor.InitNativeProcess()
       at System.Management.Automation.NativeCommandProcessor.Prepare(IDictionary psDefaultParameterValues)
       at System.Management.Automation.CommandProcessorBase.DoPrepare(IDictionary psDefaultParameterValues)
       at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean incomingStream)
       at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
    --- End of stack trace from previous location ---
       at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
       at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext
    funcContext)
       at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
       at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
        Message        : Program 'test.py' failed to run: Only one of Arguments or ArgumentList may be used.At line:1 char:1
                         + ./test.py someargs
                         + ~~~~~~~~~~~~~~~~~~.
        Data           : System.Collections.ListDictionaryInternal
        InnerException :
            Type       : System.InvalidOperationException
            TargetSite :
                Name          : Start
                DeclaringType : System.Diagnostics.Process
                MemberType    : Method
                Module        : System.Diagnostics.Process.dll
            StackTrace :
       at System.Diagnostics.Process.Start()
       at System.Management.Automation.NativeCommandProcessor.InitNativeProcess()
            Message    : Only one of Arguments or ArgumentList may be used.
            Source     : System.Diagnostics.Process
            HResult    : -2146233079
        Source         : System.Management.Automation
        HResult        : -2146233087
    CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
    FullyQualifiedErrorId : NativeCommandFailed
    InvocationInfo        :
        ScriptLineNumber : 1
        OffsetInLine     : 1
        HistoryId        : -1
        Line             : ./test.py someargs
        PositionMessage  : At line:1 char:1
                           + ./test.py someargs
                           + ~~~~~~~~~~~~~~~~~~
        CommandOrigin    : Internal
    ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

    Edit: I should mention that this issue is fixed when setting $PSNativeCommandArgumentPassing="Standard"

  5. added
    Issue-BugIssue has been identified as a bug in the product
    and removed
    Needs-TriageThe issue is new and needs to be triaged by a work group.
    on May 27, 2021
  6. JamesWTruher commented on May 27, 2021

    @JamesWTruher
    Collaborator

    yep - this is a bug for which I have a fix

  7. kilasuit commented on May 18, 2022

    @kilasuit
    Collaborator

    James Truher (@JamesWTruher) any chance we can get your fix in for this any time soon?

  8. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  9. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  10. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions