Exception when running with ToTask()
vpenades opened this issue · comments
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:
- clone https://github.com/vpenades/GltfValidator.git
- run test Test1Async
thanks for reporting.
However can not find Test1Async code in your repository.
here's the link for Test1Async
Currently if data exists in StdError, ProcessX throws error.
If you want to ignore stderror result, use GetDualAsyncEnumerable.
public static async Task<ValidationReport> ValidateFileAsyncProcessX(string gltfFilePath, System.Threading.CancellationToken token)
{
var psi = CreateStartInfo(gltfFilePath);
var (_, stdout, stderror) = Cysharp.Diagnostics.ProcessX.GetDualAsyncEnumerable(psi);
var lines = await stdout.ToTask(); // ignore stderror
return ValidationReport.Parse(string.Join("\r\n", lines));
}
That solved the problem, thanks for the fast reply!