Skip to content

Releases

v2.0.0

Choose a tag to compare

@github-actions github-actions released this 19 Nov 12:18

ProcessX v2

ProcessX v2 is a complete rewrite and a breaking change. It is not a drop-in update from v1.

  • v2 requires .NET 11. If you are on .NET 10 or earlier, please keep using v1 (1.5.6). It remains available on NuGet.
  • Why a rewrite. .NET 11 improved the Process API, and what ProcessX v1 was made for (ProcessX.StartAsync: simple, asynchronous process execution) is now covered by the BCL (Process.ReadAllLinesAsync, Process.RunAndCaptureTextAsync).
  • What v2 is. v2 focuses on what the BCL does not provide: writing shell scripts in C#, like google/zx. It is built on the new Process API and works especially well with file-based apps (dotnet run build.cs).
#!/usr/bin/env dotnet
#:package ProcessX@2.*
using ProcessX;
using static ProcessX.Zx;

// `await string` runs it through the shell and returns stdout
await "dotnet --list-sdks | sort";

// receive stdout as a string, and pass it to the next command with run($"...")
var branch = await "git branch --show-current";
await run($"git push origin {branch}");

// execute in parallel
var (dotnet, git, msg) = await (
    run("dotnet --version"),
    run("git --version"),
    sh("echo foo")
);

What's new

Three ways to run a command

  • run($"...") starts the process directly, without a shell. Each {hole} is passed as one argument, so a value never needs quoting or escaping. A sequence expands to one argument per element.
  • sh($"...") runs through the shell (pipes, redirects, built-ins, batch files). Each {hole} is quoted for the current shell: bash/sh, pwsh or cmd.exe. {value:raw} inserts script text on purpose.
  • await "..." is the short form for a constant script.

Command options

run and sh return a Command that starts when awaited, so options can be chained: NoThrow(), Quiet(), Inherit(), Timeout(), WithCancellation(), GracePeriod(), Cwd(), SetEnv(), Input(), WithEncoding().

Composition

  • Pipe: run($"git log --oneline") | run($"grep {pattern}") connects processes with an OS pipe, without a shell.
  • Parallel: await a tuple or a sequence of commands.
  • Streaming: await foreach (var line in run($"...")).
  • Binary output: ToBytesAsync() and ToStreamAsync(stream).
  • Standard input: Input(string | byte[] | Stream), the way to pass a secret without putting it in the command line.

Safer by default

  • A non-zero exit code throws ProcessErrorException. Output on stderr alone is not an error.
  • The built-in shells are set up so that a failure inside a script is not lost (set -euo pipefail for bash, and equivalents for sh and pwsh).
  • Processes do not outlive the script: a stopped command is killed with its whole process tree, and children are killed when the script exits (Windows and Linux).
  • A stopped process is asked to finish first where that is possible, and await returns only after it has really exited.
  • terminateToken turns Ctrl + C, Ctrl + Break and SIGTERM into a CancellationToken, so a script can clean up like trap in a shell script.
  • When a command is not found, the error says why: a shell built-in, a batch file on Windows, or a missing executable.

Ver.1.5.6

Choose a tag to compare

@github-actions github-actions released this 15 Jan 08:08
94dd0f2

What's Changed

  • Drop netcoreadpp3.1 and net5.0, use net6.0 instead. by @guitarrapc in #16
  • ci: Cysharp/Actions/.github/workflows/create-release.yaml by @guitarrapc in #17
  • ci: change upload-artifact & download-artifact to Cysharp/Actions by @guitarrapc in #19
  • ci: add depndabot.yaml to update github-actions by @guitarrapc in #18
  • chore(deps): bump technote-space/toc-generator from 2.4.0 to 4.3.1 by @dependabot in #20
  • add Env.useShell by @neuecc in #23

New Contributors

Full Changelog: 1.5.5...1.5.6

Ver.1.5.5

Choose a tag to compare

@github-actions github-actions released this 18 Oct 03:46

What's Changed

  • feat: use Cysharp/Actions reusable workflows/actions by @guitarrapc in #13
  • Avoid reading StdOut stream when process failed on invalid exit code with StdErr content by @mataness in #12

New Contributors

Full Changelog: 1.5.4...1.5.5

Ver.1.5.4

Choose a tag to compare

@github-actions github-actions released this 11 Jan 06:26
  • Fix Zx, does not work on Linux/MacOS

Ver.1.5.3

Choose a tag to compare

@github-actions github-actions released this 08 Oct 11:27
  • Add Zx, runl, processl that returns string[]

Ver.1.5.2

Choose a tag to compare

@github-actions github-actions released this 17 Sep 03:58
  • Zx, always escape if using in string

Ver.1.5.1

Choose a tag to compare

@github-actions github-actions released this 17 Sep 03:45
  • Fix, zx returns right string result(without newline)
  • Fix, ProcessAsyncEnumerable.FirstAsync returns right first result

Ver.1.5.0

Choose a tag to compare

@github-actions github-actions released this 27 Aug 03:54
  • Improve: Zx print stdError on default(verbose = true)
  • Add: Zx.Env.ignore
  • Add: Zx.Env.process2, run2, withCancellation2, withTimeout2
  • Change: Zx.Env.withTimeout, withCancellation receives only FormattableString
  • Change: FirstAsync wait process complete

Ver.1.4.5

Choose a tag to compare

@github-actions github-actions released this 23 Aug 06:27
  • Add ProcessAsyncEnumerable.WaitAsync

Ver.1.4.4

Choose a tag to compare

@github-actions github-actions released this 23 Aug 06:16
  • Add ProcessAsyncEnumerable.FirstAsync, FirstOrDefaultAsync