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.
-- v13: 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/Makefile.in | 2 +- programs/wmic/main.c | 48 +++++++++++++++++++++++++++++++++++---- programs/wmic/wmic.h | 1 + programs/wmic/wmic.rc | 1 + 4 files changed, 47 insertions(+), 5 deletions(-)
diff --git a/programs/wmic/Makefile.in b/programs/wmic/Makefile.in index 973232f8480..83a9539ea38 100644 --- a/programs/wmic/Makefile.in +++ b/programs/wmic/Makefile.in @@ -1,5 +1,5 @@ MODULE = wmic.exe -IMPORTS = oleaut32 ole32 user32 +IMPORTS = oleaut32 ole32 user32 shell32
EXTRADLLFLAGS = -mconsole -municode
diff --git a/programs/wmic/main.c b/programs/wmic/main.c index 936fe45139d..7bf293b6ca3 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,14 +335,12 @@ done: return ret; }
-int __cdecl wmain(int argc, WCHAR *argv[]) +static int process_args( int argc, WCHAR *argv[] ) { const WCHAR *class, *value; int i;
- setlocale( LC_ALL, "" ); - - for (i = 1; i < argc && argv[i][0] == '/'; i++) + for (i = 0; i < argc && argv[i][0] == '/'; i++) WINE_FIXME( "command line switch %s not supported\n", debugstr_w(argv[i]) );
if (i >= argc) @@ -391,3 +391,43 @@ 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"wmic:root\cli>", stdout ); + + while (fgetws(cmd, sizeof(cmd), stdin) != NULL) + { + 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( strip_spaces(cmd), &_argc ); + ret = process_args( _argc, _argv ); + LocalFree(_argv); + + output_newline(); + } + fputws( L"wmic:root\cli>", stdout ); + } + return ret; + } + + return process_args( argc - 1, &argv[1] ); +} 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 , I addressed first issue you mention, but I don't really get your second remark about "process_args() then doesn't need to handle command line switches"
On windows in interactive mode switches are supported as well (like /failfast:on os get name), so why take them out? Afaict they should be treated both in interactive and "normal" mode same way.
Please also note that the goal of this patch was not to make interactive mode work but to make the command of bug https://bugs.winehq.org/show_bug.cgi?id=56361 work ("bios get status | wmic").
So if things in interactive mode might need improvement, then that could be addressed in other patches or not?
Right, but the word 'command line' doesn't make sense in interactive mode. I'll send a patch afterwards to fix that up.
This merge request was approved by Hans Leidekker.