From: Bernhard Übelacker Subject: [PATCH] cmd: Avoid having first parameter to start.exe ignored. Message-Id: <20180127160337.21819-1-bernhardu@mailbox.org> Date: Sat, 27 Jan 2018 17:03:37 +0100 https://bugs.winehq.org/show_bug.cgi?id=44334 Found while trying to look into #44236. A batch script is executed but the start commands do not wait until the started process ends. Example line: --- start /W " " "%SFDIR%automesh" wr2300 --- As far as I see this happens when WCMD_start encounters an title parameter. Then it removes the executable from the cmdline parameter to CreateProcessW. --- start /W "" notepad 002f:trace:process:create_process_impl app L"C:\\windows\\command\\start.exe" cmdline L"/W \"\\\"\\\"\" notepad" --- This get not recognized much, because usually the title is the first parameter and is therefore ignored by start.exe. This patch tries to maintain the executable as first parameter in the cmdline parameter to CreateProcessW. Signed-off-by: Bernhard Übelacker --- programs/cmd/builtins.c | 14 ++++++++------ programs/cmd/tests/test_builtins.cmd | 4 ++++ programs/cmd/tests/test_builtins.cmd.exp | 2 ++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c index 14961d7922..257a948506 100644 --- a/programs/cmd/builtins.c +++ b/programs/cmd/builtins.c @@ -4323,6 +4323,7 @@ void WCMD_start(WCHAR *args) int have_title; WCHAR file[MAX_PATH]; WCHAR *cmdline; + WCHAR *cmdline_params; STARTUPINFOW st; PROCESS_INFORMATION pi; @@ -4331,6 +4332,7 @@ void WCMD_start(WCHAR *args) cmdline = heap_alloc( (strlenW(file) + strlenW(args) + 8) * sizeof(WCHAR) ); strcpyW( cmdline, file ); strcatW( cmdline, spaceW ); + cmdline_params = cmdline + strlenW(file) + strlenW(spaceW); /* The start built-in has some special command-line parsing properties * which will be outlined here. @@ -4382,17 +4384,17 @@ void WCMD_start(WCHAR *args) have_title = TRUE; /* Copy all of the cmdline processed */ - memcpy(cmdline, args, sizeof(WCHAR) * (argN - args)); - cmdline[argN - args] = '\0'; + memcpy(cmdline_params, args, sizeof(WCHAR) * (argN - args)); + cmdline_params[argN - args] = '\0'; /* Add quoted title */ - strcatW(cmdline, prefixQuote); - strcatW(cmdline, thisArg); - strcatW(cmdline, postfixQuote); + strcatW(cmdline_params, prefixQuote); + strcatW(cmdline_params, thisArg); + strcatW(cmdline_params, postfixQuote); /* Concatenate remaining command-line */ thisArg = WCMD_parameter_with_delims(args, argno, &argN, TRUE, FALSE, startDelims); - strcatW(cmdline, argN + strlenW(thisArg)); + strcatW(cmdline_params, argN + strlenW(thisArg)); break; } diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd index 62334b17b6..b8b2a7a6b8 100644 --- a/programs/cmd/tests/test_builtins.cmd +++ b/programs/cmd/tests/test_builtins.cmd @@ -2978,6 +2978,10 @@ path set path=%WINE_backup_path% set WINE_backup_path= +echo ------------ Testing start /W ------------ +echo start /W failed to wait>foobar.txt +start /W "" cmd /C "ping -n1 & echo start /W seems to really wait>foobar.txt"& type foobar.txt& del foobar.txt + echo ------------ Testing combined CALLs/GOTOs ------------ echo @echo off>foo.cmd echo goto :eof>>foot.cmd diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp index 796550e57e..a32c8fe25e 100644 --- a/programs/cmd/tests/test_builtins.cmd.exp +++ b/programs/cmd/tests/test_builtins.cmd.exp @@ -1571,6 +1571,8 @@ Correctly ignored trailing information PATH=original PATH=try2 PATH=try3 +------------ Testing start /W ------------ +start /W seems to really wait ------------ Testing combined CALLs/GOTOs ------------ world cheball -- 2.15.1