I need to control a console application written in C++ from C# app.
The C# app can't read anything from output of C++ app. The application freezes when using the function process.StandardOutput.ReadLine()
. I tried to create simple console apps in C#, C++ only with printf("Test sample\r\n") and Console.WriteLine("Test sample"). And the sample C# app works great, C++ not. So I don't know where I'm making a mistake. Probably C++ app writes bad end of line but I don't know how to solve it.
A code sample of main app in C# which controls another app written in C++ or C#.
process= new Process()
{
StartInfo = new ProcessStartInfo(@"testApp")
{
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = false,
WindowStyle = ProcessWindowStyle.Hidden
}
};
process.Start();
inputWriter = process.StandardInput;
string text =process.StandardOutput.ReadLine();//C++ app freezes here
And two test applications
In C++
int main(){
while (true) {
std::this_thread::sleep_for(std::chrono::milliseconds(500));
printf("Test send data\r\n");
}
return 0;}
In C#
static void Main(string[] args)
{
while (true)
{
Thread.Sleep(500);
Console.WriteLine("Test send data");
}
}