On Fri Jul 18 10:08:35 2025 +0000, eric pouech wrote:
I'm still thinking of the best approach...
- on one hand, using an invalid handle as default for stdin, even if a
valid situation, is not the most common
- on the other hand, using NUL input, or CONsole's input, or a pipe:d
string is doable from tests; I don't see a simple way of using an invalid handle from the tests so if we want to be able to cover all possible test cases, keeping current invalid handle as default is perhaps the best solution if we now consider what we're testing, there are a couple of tests which don't take care of explicitely defining their input (while they should, as behavior depends on input) from that, there are likely a bunch of them for which return_code/errorlevel will only differ because of the read(stdin) result (error for invalid handle vs empty buffer for NUL). of course, there are a few others (CHOICE coming to mind first) where defining input is a must have. Passing input handle in CreateProcess will block input, hence identify the potential culprits. But this will be another pain on test writer to understand why the test times out. Perhaps, having a first shot at which tests trigger reading from input could help in deciding on best approach. how to you get the issues with find? AFAICS the cmd.exe tests only use the form with a path specified, which shouldn't read from stdin. so maybe there's something else lurking here
I completely agree find shouldn't touch stdin unless arguments say it should
but it does ```c #include <windows.h>
int main(int argc, char** argv) { SECURITY_ATTRIBUTES sa = { sizeof(sa), 0, TRUE }; STARTUPINFOA si = { sizeof(si) }; PROCESS_INFORMATION pi; HANDLE stdout = GetStdHandle(STD_OUTPUT_HANDLE); HANDLE nul = CreateFileA("NUL", GENERIC_READ, FILE_SHARE_WRITE|FILE_SHARE_READ, &sa, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); DWORD dummy; WriteFile(stdout, "first\r\n", strlen("first\r\n"), &dummy, NULL); si.dwFlags = STARTF_USESTDHANDLES; si.hStdInput = NULL; si.hStdOutput = stdout; si.hStdError = stdout; CreateProcessA(NULL, "cmd /c find /?", NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi); WaitForSingleObject(pi.hProcess, INFINITE); WriteFile(stdout, "second\r\n", strlen("second\r\n"), &dummy, NULL); si.hStdInput = nul; CreateProcessA(NULL, "cmd /c find /?", NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi); WaitForSingleObject(pi.hProcess, INFINITE); WriteFile(stdout, "done\r\n", strlen("done\r\n"), &dummy, NULL); return 0; } ```