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.
-- v4: fix typo
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..bb095169c8b 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_INTERACTIVE 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/wmic.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/programs/wmic/wmic.h b/programs/wmic/wmic.h index bb095169c8b..fef2113feb0 100644 --- a/programs/wmic/wmic.h +++ b/programs/wmic/wmic.h @@ -22,4 +22,4 @@ #define STRING_ALIAS_NOT_FOUND 102 #define STRING_INVALID_QUERY 103 #define STRING_INVALID_PATH 104 -#define STRING_INTERACTIVE 105 +#define STRING_USAGE 105