I'm trying to launch a Python Tkinter app from C#. That app uses stdin and stdout beside its GUI. How can I launch it from a dotnet Core app so that I can access its stdin/stdout?
If I use UseShellExecute=false
I can redirect the streams, but the GUI will not appear. If I use UseShellExecute=true
the GUI appears, but the streams cannot be redirected.
I also tried starting the process with cmd /c py ...
instead of just py ...
. Still, the GUI does not appear in UseShellExecute=false
mode.
Update:
At this point it seems like the issue is somehow python related. The code below works, and the window appears at mainloop()
, but only at mainloop()
. This is NOT how the same app behaves if I run it directly from cmd. In that case the GUI already appears before the input is given. What can cause this difference in behavior?
var psi = new ProcessStartInfo
{
FileName = "py",
Arguments = @"s:\dsgui\ex.py",
RedirectStandardInput = true,
RedirectStandardOutput = true,
UseShellExecute = false
};
var process = Process.Start(psi);
process.StandardInput.WriteLine("test");
ex.py:
import tkinter
tkinter.Tk()
print(input())
tkinter.mainloop()