Search code examples
c#c#-interactivecsi

How to access command line arguments in .csx script?


I'm using csi.exe the C# Interactive Compiler to run a .csx script. How can I access any command line arguments supplied to my script?

csi script.csx 2000

If you're not familiar with csi.exe, here's the usage message:

>csi /?
Microsoft (R) Visual C# Interactive Compiler version 1.3.1.60616
Copyright (C) Microsoft Corporation. All rights reserved.

Usage: csi [option] ... [script-file.csx] [script-argument] ...

Executes script-file.csx if specified, otherwise launches an interactive REPL (Read Eval Print Loop).

Solution

  • Environment.GetCommandLineArgs() returns ["csi", "script.csx", "2000"] for that example.