4

I have a strange situation where running the cli from a .net Process.Start() it works all of the time (on tested addresses), but on 1 address it just freezes - process.WaitForExit() never exits. When the cli is run from the command line - I get all results as expected. Pretty sure this is something with Process.Start(), but for the life of me I can't figure it out.

Addresses below

Works (Arguments) - has about 8 UTXOs
query utxo --address addr_test1qz065xj60utnn4d0wmnc3aqt84w73vwlegmpves5v8pyrh5mm26227qq66j3uzr38xn5gy9swm7h4g3lxu8u0nqzddjquz6fqm  --testnet-magic 1097911063

Locks up (Arguments) - has about 40 UTXOs
query utxo --address addr_test1qz7mvmykanj59dz49ef5lvvn0yymmsj77w2pjfynkf3an2vq3jtd2jajxyfylhvpxskdyeum4s6rr4x08kl28r4hc72sskhe6g  --testnet-magic 1097911063

Also I know this should be an async function - but I'll sort that later ;-)

public CardanoCliResult Cli(List<string> arguments, bool useNetwork = false, bool useEra = false) {
    if (useNetwork) arguments.Add($" {_network}");
    if (useEra) arguments.Add($" {_era}");
    ProcessStartInfo start = new ProcessStartInfo() {
        FileName = _cli,
        Arguments = string.Join(" ", arguments),
        UseShellExecute = false,
        RedirectStandardOutput = true,
        RedirectStandardError = true,
        CreateNoWindow = true,
    };
    start.EnvironmentVariables["CARDANO_NODE_SOCKET_PATH"] = _socket;
    
    var process = Process.Start(start);
    process.WaitForExit(); <<<<------ Locks up here
    var result = new CardanoCliResult() {
        Command = $"{_cli} {string.Join(Environment.NewLine, arguments)}{Environment.NewLine}",
        Ok = process.ExitCode == 0,
        Error = process.StandardError.ReadToEnd().Trim(),
        Output = process.StandardOutput.ReadToEnd().Trim()
    };
    ConsoleUpdateCli(result);
    return result;
}   

If anyone has an idea or has seen this before, any help would be great

Thanks


Solution I found at https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.redirectstandardoutput?view=net-5.0:

var process = Process.Start(start);
string so = process.StandardOutput.ReadToEnd();
string se = process.StandardError.ReadToEnd();
process.WaitForExit();

Hopefully it stays working

1
2

I found the answer - read the output before the wait

var process = Process.Start(start);
string so = process.StandardOutput.ReadToEnd();
string se = process.StandardError.ReadToEnd();
process.WaitForExit();

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .