+/**\r
+ Function to setup StdIn, StdErr, StdOut, and then run the command or file.\r
+\r
+ @param[in] Type the type of operation being run.\r
+ @param[in] CmdLine the command line to run.\r
+ @param[in] FirstParameter the first parameter on the command line.\r
+ @param[in] ParamProtocol the shell parameters protocol pointer\r
+\r
+ @retval EFI_SUCCESS The command was completed.\r
+ @retval EFI_ABORTED The command's operation was aborted.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SetupAndRunCommandOrFile(\r
+ IN SHELL_OPERATION_TYPES Type,\r
+ IN CHAR16 *CmdLine,\r
+ IN CHAR16 *FirstParameter,\r
+ IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol\r
+)\r
+{\r
+ EFI_STATUS Status;\r
+ SHELL_FILE_HANDLE OriginalStdIn;\r
+ SHELL_FILE_HANDLE OriginalStdOut;\r
+ SHELL_FILE_HANDLE OriginalStdErr;\r
+ SYSTEM_TABLE_INFO OriginalSystemTableInfo;\r
+\r
+ //\r
+ // Update the StdIn, StdOut, and StdErr for redirection to environment variables, files, etc... unicode and ASCII\r
+ //\r
+ Status = UpdateStdInStdOutStdErr(ParamProtocol, CmdLine, &OriginalStdIn, &OriginalStdOut, &OriginalStdErr, &OriginalSystemTableInfo);\r
+\r
+ //\r
+ // The StdIn, StdOut, and StdErr are set up.\r
+ // Now run the command, script, or application\r
+ //\r
+ if (!EFI_ERROR(Status)) {\r
+ TrimSpaces(&CmdLine);\r
+ Status = RunCommandOrFile(Type, CmdLine, FirstParameter, ParamProtocol);\r
+ }\r
+\r
+ //\r
+ // Now print errors\r
+ //\r
+ if (EFI_ERROR(Status)) {\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_ERROR), ShellInfoObject.HiiHandle, (VOID*)(Status));\r
+ }\r
+\r
+ //\r
+ // put back the original StdIn, StdOut, and StdErr\r
+ //\r
+ RestoreStdInStdOutStdErr(ParamProtocol, &OriginalStdIn, &OriginalStdOut, &OriginalStdErr, &OriginalSystemTableInfo);\r
+\r
+ return (Status);\r
+}\r
+\r
+/**\r
+ Function will process and run a command line.\r
+\r
+ This will determine if the command line represents an internal shell \r
+ command or dispatch an external application.\r
+\r
+ @param[in] CmdLine The command line to parse.\r
+\r
+ @retval EFI_SUCCESS The command was completed.\r
+ @retval EFI_ABORTED The command's operation was aborted.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RunCommand(\r
+ IN CONST CHAR16 *CmdLine\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ CHAR16 *CleanOriginal;\r
+ CHAR16 *FirstParameter;\r
+ CHAR16 *TempWalker;\r
+ SHELL_OPERATION_TYPES Type;\r
+\r
+ ASSERT(CmdLine != NULL);\r
+ if (StrLen(CmdLine) == 0) {\r
+ return (EFI_SUCCESS);\r
+ }\r
+\r
+ Status = EFI_SUCCESS;\r
+ CleanOriginal = NULL;\r
+\r
+ CleanOriginal = StrnCatGrow(&CleanOriginal, NULL, CmdLine, 0);\r
+ if (CleanOriginal == NULL) {\r
+ return (EFI_OUT_OF_RESOURCES);\r
+ }\r
+\r
+ TrimSpaces(&CleanOriginal);\r
+\r
+ //\r
+ // NULL out comments (leveraged from RunScriptFileHandle() ).\r
+ // The # character on a line is used to denote that all characters on the same line\r
+ // and to the right of the # are to be ignored by the shell.\r
+ // Afterward, again remove spaces, in case any were between the last command-parameter and '#'.\r
+ //\r
+ for (TempWalker = CleanOriginal; TempWalker != NULL && *TempWalker != CHAR_NULL; TempWalker++) {\r
+ if (*TempWalker == L'^') {\r
+ if (*(TempWalker + 1) == L'#') {\r
+ TempWalker++;\r