Pipe is being closed. Trying to pass request body to php process
I am trying to open a php process in my kestrel middleware. Without body everything works fine, but sending a body throws the exception Pipe is being closed. Do you know why?
9 Replies
.StandardInput of phpProcess is already a StreamWriter, try eliminating the
await using StreamWriter sw = new(phpProcess.StandardInput.BaseStream);
@occluder Like this?
Same exception
@レオン Why not just
phpProcess.StandardInput.WriteAsync
?
you are flushing StandardInput without using any of the write methods on itMy fault, but hasnt changed anything. The exception occurs on the write method. Same for this one:
Interesting, perhaps the process is somehow ending before you get a chance to write anything? I've come across this: https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/8.0/filestream-disposed-pipe
.NET 8 breaking change: FileStream writes when pipe is closed - .NET
Learn about the .NET 8 breaking change in core .NET libraries where an exception is thrown if you write to a FileStream whose underlying pipe is closed.
@レオン check phpProcess.HasExited before writing, otherwise your code looks like it should work. If it doesn't I would suggest using CliWrap from nuget rather than dealing with the process class
HasExited is true. That seems to be the problem. Now I have to check how can I let the process wait for my inputs
Maybe you got the filename or arguments wrong? Process.Start() returns bool, that might help out
Process.Start()
returned true. I have moved over to CliWrap.
Thats my code. Sadly same result, blank screen while executing a script with a body
I found the main issue. The script sets the header location and this is not supported. I have removed the php script and replaced it with html/js + api. Thanks for help. Even we havnt found a solution I have learned few new things. The solution (havnt tried yet) is to call the fastcgi service e.g. php-fpm, but there is no active maintained wrapper for .net