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.
-- v7: wmic.exe: Support interactive mode and piped commands.
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 | 46 ++++++++++++++++++++++++++++++++++++++++++- programs/wmic/wmic.h | 1 + programs/wmic/wmic.rc | 1 + 3 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/programs/wmic/main.c b/programs/wmic/main.c index 936fe45139d..2259281677c 100644 --- a/programs/wmic/main.c +++ b/programs/wmic/main.c @@ -28,12 +28,14 @@ #include "initguid.h" #include "objidl.h" #include "wbemcli.h" +#include "shellapi.h" #include "wmic.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(wmic);
+#define MAX_STRING 4096 static const struct { const WCHAR *alias; @@ -333,7 +335,7 @@ done: return ret; }
-int __cdecl wmain(int argc, WCHAR *argv[]) +static int process_args( int argc, WCHAR *argv[] ) { const WCHAR *class, *value; int i; @@ -391,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 ); +} 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" }
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=144417
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
Hi Hans,
I pushed a new version without CreateProcess;
as I tried to keep it simple I just ripped out completely the processing of the arguments from main() into a new function. This way the amount of changed code is quite small and I don't have to reinvent the wheel of processing commands/invalid arguments. Is this something that would be acceptable?