[ros-diffs] [greatlrd] 16564: std_output does handle the : as ms does at pipe and we have also extend it to handle >test.txt: that is not vaild on ms but it should need more code to handle the : as ms does. we can call it reactos extend at cmd

greatlrd at svn.reactos.com greatlrd at svn.reactos.com
Thu Jul 14 21:19:18 CEST 2005


std_output does handle the : as ms does at pipe and we have also extend
it to handle >test.txt: that is not vaild on ms but it should need more
code to handle the : as ms does. we can call it reactos extend at cmd
Modified: trunk/reactos/subsys/system/cmd/cmd.c
  _____  

Modified: trunk/reactos/subsys/system/cmd/cmd.c
--- trunk/reactos/subsys/system/cmd/cmd.c	2005-07-14 18:39:07 UTC
(rev 16563)
+++ trunk/reactos/subsys/system/cmd/cmd.c	2005-07-14 19:18:37 UTC
(rev 16564)
@@ -641,17 +641,21 @@

 		HANDLE hFile;
 		SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES),
NULL, TRUE};
 
+    /* we need make sure the LastError msg is zero before calling
CreateFile */
+		SetLastError(0); 
+
+    /* Set up pipe for the standard input handler */
 		hFile = CreateFile (in, GENERIC_READ, FILE_SHARE_READ,
&sa, OPEN_EXISTING,
 		                    FILE_ATTRIBUTE_NORMAL, NULL);
 		if (hFile == INVALID_HANDLE_VALUE)
-		{
+		{      
 			LoadString(CMD_ModuleHandle, STRING_CMD_ERROR1,
szMsg, RC_STRING_MAX_SIZE);
 			ConErrPrintf(szMsg, in);
 			return;
 		}
 
 		if (!SetStdHandle (STD_INPUT_HANDLE, hFile))
-		{
+		{      
 			LoadString(CMD_ModuleHandle, STRING_CMD_ERROR1,
szMsg, RC_STRING_MAX_SIZE);
 			ConErrPrintf(szMsg, in);
 			return;
@@ -668,9 +672,7 @@
 	while (num-- > 1)
 	{
 		SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES),
NULL, TRUE};
-
     
-
     /* Create unique temporary file name */
 		GetTempFileName (szTempPath, _T("CMD"), 0,
szFileName[1]);
 
@@ -682,7 +684,7 @@
 				       TRUNCATE_EXISTING,
FILE_ATTRIBUTE_TEMPORARY, NULL);
 		
     if (hFile[1] == INVALID_HANDLE_VALUE)
-		{      
+		{            
 			LoadString(CMD_ModuleHandle, STRING_CMD_ERROR2,
szMsg, RC_STRING_MAX_SIZE);
 			ConErrPrintf(szMsg);
 			return;
@@ -715,6 +717,9 @@
 		_tcscpy (szFileName[0], szFileName[1]);
 		*szFileName[1] = _T('\0');
 
+    /* we need make sure the LastError msg is zero before calling
CreateFile */
+		SetLastError(0); 
+
 		/* open new stdin file */
 		hFile[0] = CreateFile (szFileName[0], GENERIC_READ, 0,
&sa,
 		                       OPEN_EXISTING,
FILE_ATTRIBUTE_TEMPORARY, NULL);
@@ -730,15 +735,37 @@
 		/* Final output to here */
 		HANDLE hFile;
 		SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES),
NULL, TRUE};
+		
+    /* we need make sure the LastError msg is zero before calling
CreateFile */
+		SetLastError(0); 
 
-		hFile = CreateFile (out, GENERIC_WRITE, FILE_SHARE_READ,
&sa,
+    hFile = CreateFile (out, GENERIC_WRITE, FILE_SHARE_READ, &sa,
 		                    (nRedirFlags & OUTPUT_APPEND) ?
OPEN_ALWAYS : CREATE_ALWAYS,
 		                    FILE_ATTRIBUTE_NORMAL, NULL);
-		if (hFile == INVALID_HANDLE_VALUE)
+		
+    if (hFile == INVALID_HANDLE_VALUE)
 		{
-			LoadString(CMD_ModuleHandle, STRING_CMD_ERROR3,
szMsg, RC_STRING_MAX_SIZE);
-			ConErrPrintf(szMsg, out);
-			return;
+      INT size = _tcslen(out)-1;
+      
+      if (out[size] != _T(':'))
+      {
+			   LoadString(CMD_ModuleHandle,
STRING_CMD_ERROR3, szMsg, RC_STRING_MAX_SIZE);
+			   ConErrPrintf(szMsg, out);
+			   return;
+      }
+      
+      out[size]=_T('\0');
+      hFile = CreateFile (out, GENERIC_WRITE, FILE_SHARE_READ, &sa,
+		                    (nRedirFlags & OUTPUT_APPEND) ?
OPEN_ALWAYS : CREATE_ALWAYS,
+		                    FILE_ATTRIBUTE_NORMAL, NULL);
+
+     if (hFile == INVALID_HANDLE_VALUE)
+     {
+			   LoadString(CMD_ModuleHandle,
STRING_CMD_ERROR3, szMsg, RC_STRING_MAX_SIZE);
+			   ConErrPrintf(szMsg, out);
+			   return;
+      }
+      
 		}
 
 		if (!SetStdHandle (STD_OUTPUT_HANDLE, hFile))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.reactos.org/pipermail/ros-diffs/attachments/20050714/78392718/attachment.html


More information about the Ros-diffs mailing list