Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Inconsistent argument passing in Environment.GetCommandLineArgs() and Args #749

Copy link
Copy link
Open
@Pxtl

Description

@Pxtl
Issue body actions

There are 3 different ways to run the script on Windows:

  1. dotnet script myscript.csx
  2. (after dotnet script register) just run myscript.csx
  3. compile using dotnet script publish myscript.csx and then run myscript.exe

In each of these 3 cases, the Environment.GetCommandLineArgs() contains very different data.

If called using dotnet script then the fully resolved path of the DLL is the first argument, the scriptname is the second.

C:\Users\<username>\.dotnet\tools\.store\dotnet-script\1.5.0\dotnet-script\1.5.0\tools\net8.0\any\dotnet-script.dll;myapp.csx;<user-provided-arguments-start-here>

If called using the registered version, the extra separator argument "--" is added.

C:\Users\<username>\.dotnet\tools\.store\dotnet-script\1.5.0\dotnet-script\1.5.0\tools\net8.0\any\dotnet-script.dll;myapp.csx;--;<user-provided-arguments-start-here>

Finally, if compiled to .exe it behaves a conventional way - first argument is the fully-resolved path to the .exe, all following arguments are the user-provided arguments.

I have not attempted the 4th way (executing a published DLL).

Also, the Args collection is not a good substitute, since that hides all the parameters that are intercepted by dotnet-script whereas they're available in full in Environment.GetCommandLineArgs()

It is very difficult to get a clean collection of arguments to pass onto System.Commandline

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.