Launcher

Executable Setup

WithExecutable takes a path, or a url or document, in which case whatever Windows has registered for it opens it. WithArgument is called once per argument rather than taking a command line, and quotes anything holding a space itself, so a path needs nothing done to it. WithWorkingDirectory, WithEnvironmentVariable, WithOutputTo and WithErrorTo are all settings, said before Launch, because every one of them is part of how a process is started rather than something that can be changed once it is up. The environment is added to what this process already has rather than replacing it. Asking for output or an environment means GPAL starts the process itself rather than handing it to the shell. A url cannot be opened that way, so asking for both on a url is reported as a WARNING and the url still opens.

Examples

GPAL Fluent: High-level fluent C# API

//One WithArgument per argument is why the path with a space in it needs nothing: GPAL quotes it as it builds the command line. A single command line string would leave that to you, and getting it wrong is how a launcher quietly runs the wrong thing. Launch is the line that starts the process. Everything above it is a setting and everything after it is about the run, which is why the settings cannot be said afterwards.

// everything below is said before Launch, because it is all part of starting the process

GPAL.Launcher

.WithExecutable(@"C:MyAppapp.exe")

.WithArgument("--config=prod")

.WithArgument(@"C:Program Filesdata set.csv") // the space is quoted for you

.WithWorkingDirectory(@"C:MyApp")

.WithEnvironmentVariable("APP_ENV", "production")

.WithEnvironmentVariable("LOG_LEVEL", "info")

.WithName("MyAppLauncher")

.Launch();


// a url or a document opens with whatever is registered for it

GPAL.Launcher

.WithExecutable("https://example.com/report.pdf")

.Launch();

💬 Ask GPAL