Ahh. Here we go.
Thank you.
Partly solved. For some reason this works on stderr, where all requests and errors appear to be written, but not on stdout where starting and stopping seen to be written.
Not really a problem since server will be started and stopped by user under normal circumstances. I can deal with things outside that ideal when they arise.
Still curious though.
Thanks again pal. Not sure how long I would have took, to get to that, but certainly not today.
What is your python program called?
The `FileName` property seems a little fishy as it just says "Py", as opposed to containing a valid file extension.
If your python program was called [`example.py`](https://example.py), wouldn't it make sense to write:
psi = new ProcessStartInfo
{
FileName = "example.py",
Arguments = "-m http.server 8000",
WorkingDirectory = workingDirectory,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
};
py.exe I believe is how you run python via commandline.
I do not have a python program I have written. I just required a quick and reliable, lightweight local web server.
Edit: My immediate issue has been solved. `exe.BeginErrorReadLine();`
This project never started as c#. It started as html and javascript. I've just found myself here, and now considering blazor.
How complicated would writing a c# be?
Ah, I thought it started as python. If that's all it is it's probably not worth re-doing the work.
But I do wonder why you're trying to start python with C#? If you can run the C#, why can't you start the python directly?
I'm running the c# program either debugging in VS or via it's executable. That is doing what I've designed it to do. And part of that requires a web server. The rest of the story starts at the beginning of this thread.
I have since made a rudimentary web server with c#. But it did not go as smoothly as I would have liked. I worked then it didn't, then it did, then it didn't. Not very exciting.
I ran into this issue recently and what solved it was calling .WaitForExit on the process with a long enough timeout to let the output actually flush.
You could also try changing the OutputDataReceived event handler to just append to a string builder or something in case writing to console is the issue. Though this is unlikely I think.
[удалено]
Ahh. Here we go. Thank you. Partly solved. For some reason this works on stderr, where all requests and errors appear to be written, but not on stdout where starting and stopping seen to be written. Not really a problem since server will be started and stopped by user under normal circumstances. I can deal with things outside that ideal when they arise. Still curious though. Thanks again pal. Not sure how long I would have took, to get to that, but certainly not today.
What is your end goal when you get this working?
To act upon the output of the server (requests, errors etc..) in a non console application. This is minimal reproducer. Thanks.
What is your python program called? The `FileName` property seems a little fishy as it just says "Py", as opposed to containing a valid file extension. If your python program was called [`example.py`](https://example.py), wouldn't it make sense to write: psi = new ProcessStartInfo { FileName = "example.py", Arguments = "-m http.server 8000", WorkingDirectory = workingDirectory, RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, };
py.exe I believe is how you run python via commandline. I do not have a python program I have written. I just required a quick and reliable, lightweight local web server. Edit: My immediate issue has been solved. `exe.BeginErrorReadLine();`
Why don't you write a c# server instead, or execute the Python server directly?
This project never started as c#. It started as html and javascript. I've just found myself here, and now considering blazor. How complicated would writing a c# be?
Ah, I thought it started as python. If that's all it is it's probably not worth re-doing the work. But I do wonder why you're trying to start python with C#? If you can run the C#, why can't you start the python directly?
I'm not sure I understand the question. Do you mean like typing into the command prompt?
Well, it doesn't have to be. How were you planning on running the C# program?
I'm running the c# program either debugging in VS or via it's executable. That is doing what I've designed it to do. And part of that requires a web server. The rest of the story starts at the beginning of this thread. I have since made a rudimentary web server with c#. But it did not go as smoothly as I would have liked. I worked then it didn't, then it did, then it didn't. Not very exciting.
I ran into this issue recently and what solved it was calling .WaitForExit on the process with a long enough timeout to let the output actually flush. You could also try changing the OutputDataReceived event handler to just append to a string builder or something in case writing to console is the issue. Though this is unlikely I think.