On Fri Jul 18 14:27:41 2025 +0000, Alfred Agrell wrote:
you'd hope so, but that'd be too easy, wouldn't it
#include <windows.h> #include <stdio.h> int main(int argc, char** argv) { SECURITY_ATTRIBUTES sa = { sizeof(sa), 0, TRUE }; STARTUPINFOA si = { sizeof(si) }; PROCESS_INFORMATION pi; HANDLE random_file = CreateFileA("C:\\Windows\\win.ini", GENERIC_READ, FILE_SHARE_WRITE|FILE_SHARE_READ, &sa, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); DWORD dummy; SetFilePointer(random_file, 1, NULL, FILE_BEGIN); si.dwFlags = STARTF_USESTDHANDLES; si.hStdInput = random_file; si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); si.hStdError = GetStdHandle(STD_OUTPUT_HANDLE); CreateProcessA(NULL, "find.exe \"aaa\" file-that-doesnt-exist.txt", NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi); WaitForSingleObject(pi.hProcess, INFINITE); printf("fp=%lu\n", SetFilePointer(random_file, 0, NULL, FILE_CURRENT)); return 0; }
wine - fp=1 of course native - fp=92 oh well, twas worth trying, would've been an improvement if it worked
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)