Obviously it isn't compiled. There is From File to be suitable to be a correct argument for stdin. However, I do not want to write my Vec to a file and then pass it as a valid argument. Is there a simple way to pass Vec in stdin?
It's because std::process::Command is a Rust interface to the underlying OS primitives (e.g. execve() or CreateProcessA()), and they don't support passing/sharing a buffer with the child process.
Passing raw data in can get tricky because it means a) the OS needs to share that chunk of the parent process's memory with the child and there's nothing stopping the parent from modifying or freeing it while the child is still running, or b) the OS would need to create a copy of the data, or c) Rust needs create a background thread to write to the child's stdin that the parent process has knowledge of or control over. None of those options are ideal, so the decision is left up to the user instead.
Is there a particular reason why you want to avoid spawn()? This seems reasonably straightforward:
let mut child = Command::new("...")
.stdin(Stdio::piped())
.stderr(Stdio::inherit())
.env_clear()
.envs(cgi_env)
.spawn()?;
let mut stdin = child.stdin.take().unwrap();
if method == "POST" {
stdin.write_all(extra.as_deref().unwrap_or_default().as_bytes())?;
stdin.flush()?;
}
drop(stdin);
let output = child.wait()?;
I do not write code nowadays. AI does the task for me. But unfortunately, I am an old schooled who considers that any process executing asynchronously will require own context, so it should consume extra memory resources and CPU power. It's the reason I have.
if method == "POST" && extra.is_some() {&extra.unwrap()
Sounds like you're transferring from a HTTP API? in that case you likely want a streaming transfer anyway rather than buffering the whole file in memory first.
So open the child with a pipe and then io::copy from the request's body as Read to the pipe as Write.
I couldn't agree more with your take 10 years ago. However servers have 1TB RAM and more nowadays. I would say that Rust even gives advantage over GC languages as Java and Go, because GC struggles with collecting garbage in such big memory space and performance of an app goes down. But your point gives another shine to implement such functionality as WebSocket, because a continuing web exchange happens in this case. Unfortunately CGI 1.1 doesn't support WebSocket and I need to propose some standard extension.