cysharp / processx Goto Github PK
View Code? Open in Web Editor NEWSimplify call an external process with the async streams in C# 8.0.
License: MIT License
Simplify call an external process with the async streams in C# 8.0.
License: MIT License
I'm trying to call process that for example compresses large data or does some video processing. This process outputs large stream of data that I would like to process it in C# ideally as some sort of a stream.
Is there a way to achieve this in ProcessX or is it something where I have should go to .NET Process class and read standard output myself?
it could be nice if methods could allow passing a CancellationToken so they can be cancelled from the outside.
I have a 3rd party executable that returns 1 when it completes successfully.
And because of ExitCode=1, ProcessX throws ProcessErrorException.
I can handle this situation by try-catch, but I'm happy if there is a way to set "acceptable" ExitCode.
Currently(rev: 09f95cb), ProcessX.StartAsync throws error when process output stderr.
This may be unexpected result in apps using stderr as logging or progress.
So I propose adding option to redirecting stderr.
In particular, add System.IO.Stream
or System.Buffers.IBufferWriter<byte>
(or char
?) to ProcessX.StartAsync
API
My console app is in E: but I need to run a program in D: from cmd. I have tried a few ways (cd.. , cd /d, etc) but nothing seems to work. Any suggestion
I'm writing a script to auto-setup a git repo (converted from an old bash script), and I noticed when I create a multi-line commit message, ProcessX messes up newlines.
Repro:
const string path = "debugMultiline";
await $"git init {path}";
await $"cd {path}";
await "git commit --allow-empty -m \"initial commit\"";
await "git commit --allow-empty -m \"await multi\nline\"";
System.Diagnostics.Process.Start("git", "commit --allow-empty -m \"Process.Start multi\nline\"");
await Cysharp.Diagnostics.ProcessX.StartAsync("git commit --allow-empty -m \"ProcessX.Start multi\nline\"").WriteLineAllAsync();
output:
[main b0ec9e6] initial commit
[main e7fdefa] await multi
[main a6db33f] Process.Start multi line
[main 7603f25] ProcessX.Start multi line
You can tell right away in the output that the second commit message is truncated (missing trailing "line"), which can be double-checked in a any git client).
Process.Start doesn't have that issue (3rd commit), nor does ProcessX.Start (4th commit).
I'm using the latest version (1.5.5) of the Nuget package.
When I run this line:
var psi = CreateStartInfo(...);
var lines = await Cysharp.Diagnostics.ProcessX
.StartAsync(psi)
.ToTask(token);
var text = string.Join("\r\n", lines);
I get this exception:
Cysharp.Diagnostics.ProcessErrorException : Process returns error, ExitCode:0
AsyncOperation`1.GetResult(Int16 token)
ProcessAsyncEnumerator.MoveNextAsync()
ProcessAsyncEnumerable.ToTask(CancellationToken cancellationToken)
ProcessAsyncEnumerable.ToTask(CancellationToken cancellationToken)
...
When calling syncronously, everything works fine.
Steps to reproduce:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.