Jason Edmeades : cmd.exe: Add basic support for FOR /
F parsing launched programs output.
Alexandre Julliard
julliard at wine.codeweavers.com
Wed Sep 12 07:50:48 CDT 2007
Module: wine
Branch: master
Commit: c7b88e95f566aa32c11512b4f15a7dbf9701413e
URL: http://source.winehq.org/git/wine.git/?a=commit;h=c7b88e95f566aa32c11512b4f15a7dbf9701413e
Author: Jason Edmeades <jason.edmeades at googlemail.com>
Date: Tue Sep 11 21:43:07 2007 +0100
cmd.exe: Add basic support for FOR /F parsing launched programs output.
---
programs/cmd/builtins.c | 38 +++++++++++++++++++++++++++++++++++---
1 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index a58acde..f58ad94 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -822,14 +822,41 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
} else if (doFileset && *itemStart != '"') {
HANDLE input;
+ WCHAR temp_file[MAX_PATH];
WINE_TRACE("Processing for filespec from item %d '%s'\n", itemNum,
wine_dbgstr_w(item));
- /* Open the file, read line by line and process */
- input = CreateFile (item, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL, NULL);
+ /* If backquote or single quote, we need to launch that command
+ and parse the results - use a temporary file */
+ if (*itemStart == '`' || *itemStart == '\'') {
+ WCHAR temp_path[MAX_PATH], temp_cmd[MAXSTRING];
+ static const WCHAR redirOut[] = {'%','s',' ','>',' ','%','s','\0'};
+ static const WCHAR cmdW[] = {'C','M','D','\0'};
+
+ /* Remove trailing character */
+ itemStart[strlenW(itemStart)-1] = 0x00;
+
+ /* Get temp filename */
+ GetTempPath (sizeof(temp_path)/sizeof(WCHAR), temp_path);
+ GetTempFileName (temp_path, cmdW, 0, temp_file);
+
+ /* Execute program and redirect output */
+ wsprintf (temp_cmd, redirOut, (itemStart+1), temp_file);
+ WCMD_execute (temp_cmd, NULL, NULL, NULL);
+
+ /* Open the file, read line by line and process */
+ input = CreateFile (temp_file, GENERIC_READ, FILE_SHARE_READ,
+ NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ } else {
+
+ /* Open the file, read line by line and process */
+ input = CreateFile (item, GENERIC_READ, FILE_SHARE_READ,
+ NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ }
+
+ /* Process the input file */
if (input == INVALID_HANDLE_VALUE) {
WCMD_print_error ();
WCMD_output (WCMD_LoadMessage(WCMD_READFAIL), item);
@@ -862,6 +889,11 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
CloseHandle (input);
}
+ /* Delete the temporary file */
+ if (*itemStart == '`' || *itemStart == '\'') {
+ DeleteFile (temp_file);
+ }
+
/* Filesets - A string literal */
} else if (doFileset && *itemStart == '"') {
WCHAR buffer[MAXSTRING] = {'\0'};
More information about the wine-cvs
mailing list