Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mklement0 opened this issue Apr 21, 2021 · 8 comments
Assignees
Labels
Issue-Bug Issue has been identified as a bug in the product Resolution-No Activity Issue has had no activity for 6 months or more WG-Engine-ParameterBinder

Comments

@mklement0
Copy link
Contributor

mklement0 commented Apr 21, 2021

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
@SteveL-MSFT
Copy link
Member

@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

@mklement0 mklement0 changed the title Experimental feature PSNativeCommandArgumentPassing breaks invocation of VBScripts with arguments Experimental feature PSNativeCommandArgumentPassing breaks invocation of WSH scripts (VBScript, JScript) with arguments Apr 22, 2021
@daxian-dbw
Copy link
Member

/cc @JamesWTruher for insight.

@End-of-Eternity
Copy link

End-of-Eternity commented May 25, 2021

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"

@JamesWTruher JamesWTruher self-assigned this May 26, 2021
@daxian-dbw daxian-dbw added Issue-Bug Issue has been identified as a bug in the product and removed Needs-Triage The issue is new and needs to be triaged by a work group. labels May 27, 2021
@JamesWTruher
Copy link
Member

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

@kilasuit
Copy link
Collaborator

@JamesWTruher any chance we can get your fix in for this any time soon?

Copy link
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.

1 similar comment
Copy link
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.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Resolution-No Activity Issue has had no activity for 6 months or more label Nov 16, 2023
Copy link
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
Labels
Issue-Bug Issue has been identified as a bug in the product Resolution-No Activity Issue has had no activity for 6 months or more WG-Engine-ParameterBinder
Projects
None yet
Development

No branches or pull requests

7 participants