<p>I found the answer - read the output before the wait</p>
<pre><code>var process = Process.Start(start);
string so = process.StandardOutput.ReadToEnd();
string se = process.StandardError.ReadToEnd();
process.WaitForExit();
</code></pre>

CC BY-SA 4.0
2021-06-17T06:29:01.320Z
2021-06-17T06:29:01.320Z
Braden
<p>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.</p>
<p>Addresses below</p>
<pre><code>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
</code></pre>
<p>Also I know this should be an async function - but I'll sort that later ;-)</p>
<pre><code>public CardanoCliResult Cli(List&lt;string&gt; arguments, bool useNetwork = false, bool useEra = false) {
    if (useNetwork) arguments.Add($&quot; {_network}&quot;);
    if (useEra) arguments.Add($&quot; {_era}&quot;);
    ProcessStartInfo start = new ProcessStartInfo() {
        FileName = _cli,
        Arguments = string.Join(&quot; &quot;, arguments),
        UseShellExecute = false,
        RedirectStandardOutput = true,
        RedirectStandardError = true,
        CreateNoWindow = true,
    };
    start.EnvironmentVariables[&quot;CARDANO_NODE_SOCKET_PATH&quot;] = _socket;
    
    var process = Process.Start(start);
    process.WaitForExit(); &lt;&lt;&lt;&lt;------ Locks up here
    var result = new CardanoCliResult() {
        Command = $&quot;{_cli} {string.Join(Environment.NewLine, arguments)}{Environment.NewLine}&quot;,
        Ok = process.ExitCode == 0,
        Error = process.StandardError.ReadToEnd().Trim(),
        Output = process.StandardOutput.ReadToEnd().Trim()
    };
    ConsoleUpdateCli(result);
    return result;
}   
</code></pre>
<p>If anyone has an idea or has seen this before, any help would be great</p>
<p>Thanks</p>
<hr />
<p><strong>Solution I found</strong> at <a href="https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.redirectstandardoutput?view=net-5.0" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.redirectstandardoutput?view=net-5.0</a>:</p>
<pre><code>var process = Process.Start(start);
string so = process.StandardOutput.ReadToEnd();
string se = process.StandardError.ReadToEnd();
process.WaitForExit();
</code></pre>
<p>Hopefully it stays working</p>

CC BY-SA 4.0
2021-06-17T06:17:29.430Z
Ok - I think I have the solution
https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.redirectstandardoutput?view=net-5.0

You need to read the output before you wait - who knew ;-).
Braden
<cardano-cli>
.NET cardano-cli query utxo Process freezes on a specific address
# .NET cardano-cli query utxo Process freezes on a specific address

(Asked by: username_0 on 2021-06-16)

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 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

**Tags:** cardano-cli
> **Comments:**
> **username_0**: Ok - I think I have the solution https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.redirectstandardoutput?view=net-5.0  You need to read the output before you wait - who knew ;-).  

---

## 1 answers

### Answer by username_0 on 2021-06-17. Score: 2 | Accepted answer

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();


---

