C
C#2y ago
ha0-sama

✅ How read text output from already started process?

I need to read data from my chess engine and below is my code
var proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "stockfish-windows-2022-x86-64-avx2.exe",
UseShellExecute = false,
RedirectStandardOutput = true,
}
};
while(true) //i know thats bad
{
StreamReader reader = proc.StandardOutput;
string line = reader.ReadLine();
Debug.WriteLine(line);
}
var proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "stockfish-windows-2022-x86-64-avx2.exe",
UseShellExecute = false,
RedirectStandardOutput = true,
}
};
while(true) //i know thats bad
{
StreamReader reader = proc.StandardOutput;
string line = reader.ReadLine();
Debug.WriteLine(line);
}
But after starting that, I am getting
System.InvalidOperationException: "StandardOut has not been redirected or the process hasn't started yet."
System.InvalidOperationException: "StandardOut has not been redirected or the process hasn't started yet."
How I can fix that? Please...
8 Replies
Buddy
Buddy2y ago
You are literally not starting the process
ha0-sama
ha0-samaOP2y ago
It is already started i need just to read data
Buddy
Buddy2y ago
where ? There is no Start method being called
ha0-sama
ha0-samaOP2y ago
by user is it possible?
Buddy
Buddy2y ago
You cannot read by a process that is already started it must be started by C# itself
ha0-sama
ha0-samaOP2y ago
oh, okay
Buddy
Buddy2y ago
Or you can use injection techniques that use IPC to communicate with your program. (Which is not recommended for most cases)
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server