Run .csx (scriptcs) C # script directly without opening a command prompt window

Is there a way on Windows to run a .csx script directly (for example, by double-clicking on a file or from the Start menu or by launching an application such as Launchy) so that the script runs in the background without opening a command prompt window?

For example, let's say I have a simple "lowercase.csx" script that simply takes any text in my clipboard, converts it to lowercase and returns the result to my clipboard. I want to be able to double-click this .csx file and run it completely in the background without opening any windows.

Currently, ScriptCS.exe and the new csi.exe launcher, which comes with the VS2015 update, will open the console window when the .csx file is run, even if this file does not output anything to the console.

Note. I know that a new window does not open if you run the script from the console window. I want to run a script in a context without a command line and not open windows.

Note2: The equivalent of what I want in "CS-Script" (an alternative to ScriptCS) is to run files using "csws.exe".

+7
c # windows scriptcs csx
source share
3 answers

scriptcs does not support this. However, there is an application that solves this problem: https://gitlab.com/Lions-Open-Source/ScriptCSW

+1
source share

You can create your own version of csi.exe , which starts without a console.

Just create a new project, make sure Type is installed in WinForms instead of the Console, then add the C # Scripting package from NuGet and copy the csi.exe source code .

+3
source share

The workaround is to create your own program that runs it in the background for you, for example, csws.exe.

Start by creating a console application.

 public static void Main(string[] args) { var startInfo = new ProcessStartInfo("path to csi.exe") { CreateNoWindow = true, Arguments = args[1], RedirectStandardOutput = true, UseShellExecute = false, }; Process.Start(startInfo); } 

(You will obviously want to pass the rest of the arguments and check that the file has been transferred, etc., but this should help get you started. And I wrote this answer on my Mac, since my Windows box is in the store, so I don’t I can guarantee that this will work.)

Then the console application does not display the window, changing it to a Windows application from the Console application on the project properties screen, as described in this question .

Finally, configure the .csx files that will always open with your application. Then you can double click on them and they will work without a window.

+2
source share

All Articles