Skip to content

Question: how to execute scripts directly from the shell as if they were executables. #664

Closed
@maximetinu

Description

@maximetinu

Hi! 👋

The documentation, in the section

https://github.com/filipw/dotnet-script#running-scripts

says that

Scripts can be executed directly from the shell as if they were executables.

How can I do that in Windows? I have tried, and the running ./helloworld.csx opens Visual Studio Code for me.

I have tried both from CMD and PowerShell.

It makes sense it opens VS Code, since that's what it says if I right click > properties any .csx that they will open with.

image

If I change it to open with dotnet-script.exe instead, at the paths of

  • C:/Users/username/.dotnet/tools/dotnet-script.exe
  • or C:/ProgramData/dotnet-script/dotnet-script/dotnet-script.exe

Then it kind of works.

  • if I double click it, it opens a cmd, runs the script and instantly closes. So I need to ad a System.Console.ReadKey() at the end of the script
  • if I run ./helloworld.csx from powershell, it does the same, it opens another CMD window and runs in there, to instantly close it afterwards.
  • if I run helloworld.csx directly from the CMD, it works as intended

I can understand that if you run it with double click from the explorer, it closes as soon as it finishes. That makes sense.

But it would be nice if it could be run directly from the powershell, instead of opening the CMD.

Any thoughts on how to achieve that behaviour? The documentation I linked at the beginning explains nothing about it.

P.S: I have already tried adding the shebang #!/usr/bin/env dotnet-script at the top of the file

Thanks in advance!

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy