Implement write_to_stdin() in std::os::process (#2482)

* SubProcess: Add write_to_stdin

* SubProcess: Change unit test for windows support
This commit is contained in:
Velikiy Kirill
2025-09-15 14:41:35 +03:00
committed by GitHub
parent 2e99ae5ab9
commit fabd96552f
2 changed files with 25 additions and 1 deletions

View File

@@ -142,4 +142,22 @@ fn void test_inherit_stdio_redirect()
assert(stdout_bytes == 0, "Should read 0 bytes from stdout");
assert(stderr_bytes == 0, "Should read 0 bytes from stderr");
}
}
fn void test_write_to_stdin() @test {
$if env::WIN32:
SubProcess? subprocess = process::create({`powershell`, `-C`, `Read-Host`}, {.inherit_environment = true});
$else
SubProcess? subprocess = process::create({"tee"}, {.read_async = true});
$endif
test::eq(@ok(subprocess), true);
usz? write = subprocess!!.write_to_stdin(")");
test::eq(@ok(write), true);
test::eq(write!!, 1);
char buf;
test::eq(@ok(subprocess!!.join()), true);
usz? read = subprocess!!.read_stdout(&buf, 1);
test::eq(@ok(read), true);
test::eq(read!!, 1);
test::eq(buf, ')');
}