On Sat Jul 19 07:57:54 2025 +0000, eric pouech wrote:
thanks for looking into it... looks like find is handling pipes differently from files
diff --git a/programs/cmd/tests/batch.c b/programs/cmd/tests/batch.c index 03a05f34215..f066f0617ce 100644 --- a/programs/cmd/tests/batch.c +++ b/programs/cmd/tests/batch.c @@ -111,7 +111,9 @@ static BOOL run_cmd(const char *res_name, const char *cmd_data, DWORD cmd_size) char command_cmd[] = "test.cmd", command_bat[] = "test.bat"; char *command; STARTUPINFOA si = {sizeof(si)}; + SIZE_T input_watch_dog_size = 0; PROCESS_INFORMATION pi; + HANDLE rpipe, wpipe; HANDLE file,fileerr; DWORD size; BOOL bres; @@ -143,23 +145,42 @@ static BOOL run_cmd(const char *res_name, const char *cmd_data, DWORD cmd_size) if(fileerr == INVALID_HANDLE_VALUE) return FALSE; + if ((bres = CreatePipe(&rpipe, &wpipe, &sa, 0))) + { + char buffer[64]; + memset(buffer, 26 /* ctrl-Z */, sizeof(buffer)); + bres = WriteFile(wpipe, buffer, sizeof(buffer), &size, NULL) && + size == sizeof(buffer); + input_watch_dog_size = sizeof(buffer); + } + else rpipe = wpipe = INVALID_HANDLE_VALUE; + ok(bres, "Couldn't create pipe for input\n"); + si.dwFlags = STARTF_USESTDHANDLES; + si.hStdInput = rpipe; si.hStdOutput = file; si.hStdError = fileerr; bres = CreateProcessA(NULL, command, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi); ok(bres, "CreateProcess failed: %lu\n", GetLastError()); - if(!bres) { - DeleteFileA("test.out"); - return FALSE; - } - WaitForSingleObject(pi.hProcess, INFINITE); - CloseHandle(pi.hThread); - CloseHandle(pi.hProcess); + if (bres) + { + WaitForSingleObject(pi.hProcess, INFINITE); + ok(PeekNamedPipe(rpipe, NULL, 0, NULL, &size, NULL), "Couldn't access read pipe\n"); + ok(size == input_watch_dog_size, "Invalid test, some command reads from stdin (%lu <> %Iu)\n", size, input_watch_dog_size); + CloseHandle(pi.hThread); + CloseHandle(pi.hProcess); + } + else + DeleteFileA("test.out"); CloseHandle(file); CloseHandle(fileerr); + CloseHandle(rpipe); + CloseHandle(wpipe); + DeleteFileA(command); - return TRUE; + + return bres; } static DWORD map_file(const char *file_name, const char **ret)
technically speaking:
- this seems to work as expected. (contains other cleanup:s to handle
error cases from CreateProcess)
- without your changes to `DATE` & `TIME` tests, it fails on Wine
triggering the test about stdin being read.
- with your changes to `DATE` & `TIME` tests, all tests pass on Wine.
- On native (only tested Win10), some errors (about `DEL` & friends) are
reported (as find has now a valid stdin)
NULL handle, NUL file, random regular file, console, pipe... sure got a lot of options here.
Sure, pipe sounds like the best one.