See also https://bugs.winehq.org/show_bug.cgi?id=56361
This patch makes piped commands work like for example "echo os get version|wmic" or "type file.txt | wmic" where file.txt contains some commands. (probably used by program in aforementioned bugreport)
Also support interactive mode (wine wmic.exe)
Marked for now as draft.
-- v6: put processing args in seperate function
From: Louis Lenders xerox.xerox2000x@gmail.com
See also https://bugs.winehq.org/show_bug.cgi?id=56361
This patch makes piped commands work like for example "echo os get version|wmic" or "type file.txt | wmic" where file.txt contains some commands. (probably used by program in aforementioned bugreport)
Also support interactive mode (wine wmic.exe) --- programs/wmic/main.c | 35 +++++++++++++++++++++++++++++++++++ programs/wmic/wmic.h | 1 + programs/wmic/wmic.rc | 1 + 3 files changed, 37 insertions(+)
diff --git a/programs/wmic/main.c b/programs/wmic/main.c index 936fe45139d..da84bf04097 100644 --- a/programs/wmic/main.c +++ b/programs/wmic/main.c @@ -34,6 +34,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(wmic);
+#define MAX_STRING 4096 static const struct { const WCHAR *alias; @@ -337,9 +338,43 @@ int __cdecl wmain(int argc, WCHAR *argv[]) { const WCHAR *class, *value; int i; + WCHAR cmd[MAX_STRING];
setlocale( LC_ALL, "" );
+ if (argc == 1) + { + STARTUPINFOW si = {0}; + PROCESS_INFORMATION pi = {0}; + + fputws( L"wbem:root\cli>", stdout ); + + while (fgetws(cmd, sizeof(cmd), stdin) != NULL) + { + WCHAR wmic[MAX_STRING] = L"wmic.exe "; + + cmd[wcslen(cmd)-1] = 0; /* remove trailing '\n' */ + + WINE_FIXME("command: %s\n", debugstr_w(cmd)); + if (!wcsicmp( strip_spaces(cmd), L"exit" ) || !wcsicmp( strip_spaces(cmd), L"quit" )) + return 0; + + if (!cmd[0]) + output_error( STRING_USAGE ); + else + { + CreateProcessW( 0, wcscat( wmic, cmd ), 0, 0, 0, 0, 0, 0, &si, &pi ); + WaitForSingleObject( pi.hProcess, INFINITE ); + CloseHandle( pi.hProcess ); + CloseHandle( pi.hThread ); + + output_newline(); + } + fputws( L"wbem:root\cli>", stdout ); + } + return 0; + } + for (i = 1; i < argc && argv[i][0] == '/'; i++) WINE_FIXME( "command line switch %s not supported\n", debugstr_w(argv[i]) );
diff --git a/programs/wmic/wmic.h b/programs/wmic/wmic.h index 27272706af5..fef2113feb0 100644 --- a/programs/wmic/wmic.h +++ b/programs/wmic/wmic.h @@ -22,3 +22,4 @@ #define STRING_ALIAS_NOT_FOUND 102 #define STRING_INVALID_QUERY 103 #define STRING_INVALID_PATH 104 +#define STRING_USAGE 105 diff --git a/programs/wmic/wmic.rc b/programs/wmic/wmic.rc index 0789ef34631..797fe7dbe08 100644 --- a/programs/wmic/wmic.rc +++ b/programs/wmic/wmic.rc @@ -28,4 +28,5 @@ STRINGTABLE STRING_ALIAS_NOT_FOUND, "Error: Alias not found\n" STRING_INVALID_QUERY, "Error: Invalid query\n" STRING_INVALID_PATH, "Error: Invalid syntax for PATH\n" + STRING_USAGE, "Supply a command\n" }
From: Louis Lenders xerox.xerox2000x@gmail.com
--- programs/wmic/main.c | 79 ++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 35 deletions(-)
diff --git a/programs/wmic/main.c b/programs/wmic/main.c index da84bf04097..2259281677c 100644 --- a/programs/wmic/main.c +++ b/programs/wmic/main.c @@ -28,6 +28,7 @@ #include "initguid.h" #include "objidl.h" #include "wbemcli.h" +#include "shellapi.h" #include "wmic.h"
#include "wine/debug.h" @@ -334,47 +335,13 @@ done: return ret; }
-int __cdecl wmain(int argc, WCHAR *argv[]) +static int process_args( int argc, WCHAR *argv[] ) { const WCHAR *class, *value; int i; - WCHAR cmd[MAX_STRING];
setlocale( LC_ALL, "" );
- if (argc == 1) - { - STARTUPINFOW si = {0}; - PROCESS_INFORMATION pi = {0}; - - fputws( L"wbem:root\cli>", stdout ); - - while (fgetws(cmd, sizeof(cmd), stdin) != NULL) - { - WCHAR wmic[MAX_STRING] = L"wmic.exe "; - - cmd[wcslen(cmd)-1] = 0; /* remove trailing '\n' */ - - WINE_FIXME("command: %s\n", debugstr_w(cmd)); - if (!wcsicmp( strip_spaces(cmd), L"exit" ) || !wcsicmp( strip_spaces(cmd), L"quit" )) - return 0; - - if (!cmd[0]) - output_error( STRING_USAGE ); - else - { - CreateProcessW( 0, wcscat( wmic, cmd ), 0, 0, 0, 0, 0, 0, &si, &pi ); - WaitForSingleObject( pi.hProcess, INFINITE ); - CloseHandle( pi.hProcess ); - CloseHandle( pi.hThread ); - - output_newline(); - } - fputws( L"wbem:root\cli>", stdout ); - } - return 0; - } - for (i = 1; i < argc && argv[i][0] == '/'; i++) WINE_FIXME( "command line switch %s not supported\n", debugstr_w(argv[i]) );
@@ -426,3 +393,45 @@ not_supported: output_error( STRING_CMDLINE_NOT_SUPPORTED ); return 1; } + +int __cdecl wmain(int argc, WCHAR *argv[]) +{ + WCHAR cmd[MAX_STRING]; + int ret = 0; + + setlocale( LC_ALL, "" ); + + if (argc == 1) + { + fputws( L"wbem:root\cli>", stdout ); + + while (fgetws(cmd, sizeof(cmd), stdin) != NULL) + { + WCHAR wmic[MAX_STRING] = L"wmic.exe "; + + cmd[wcslen(cmd)-1] = 0; /* remove trailing '\n' */ + + WINE_TRACE("command: %s\n", debugstr_w(cmd)); + if (!wcsicmp( strip_spaces(cmd), L"exit" ) || !wcsicmp( strip_spaces(cmd), L"quit" )) + return 0; + + if (!cmd[0]) + output_error( STRING_USAGE ); + else + { + int _argc; + WCHAR **_argv; + + _argv = CommandLineToArgvW( wcscat( wmic, cmd ), &_argc ); + ret = process_args( _argc, _argv ); + LocalFree(argv); + + output_newline(); + } + fputws( L"wbem:root\cli>", stdout ); + } + return ret; + } + + return process_args( argc, argv ); +}
Hi,
It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated.
The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=144416
Your paranoid android.
=== debian11 (build log) ===
/home/winetest/tools/testbot/var/wine-win32/../wine/programs/wmic/main.c:425: undefined reference to `_imp__CommandLineToArgvW@8' collect2: error: ld returned 1 exit status Task: The win32 Wine build failed
=== debian11b (build log) ===
/home/winetest/tools/testbot/var/wine-wow64/../wine/programs/wmic/main.c:425: undefined reference to `__imp_CommandLineToArgvW' collect2: error: ld returned 1 exit status Task: The wow64 Wine build failed