mirror of
https://github.com/reactos/reactos.git
synced 2024-12-27 01:24:38 +00:00
implemented batch redirection by saving batch info in tagBATCHCONTEXT by Brandon Turner
svn path=/trunk/; revision=17423
This commit is contained in:
parent
598f28ffad
commit
13b5d61c2c
5 changed files with 62 additions and 8 deletions
|
@ -218,10 +218,10 @@ VOID ExitBatch (LPTSTR msg)
|
|||
BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param)
|
||||
{
|
||||
HANDLE hFile;
|
||||
|
||||
SetLastError(0);
|
||||
hFile = CreateFile (fullname, GENERIC_READ, FILE_SHARE_READ, NULL,
|
||||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL |
|
||||
FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
||||
FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
||||
|
||||
#ifdef _DEBUG
|
||||
DebugPrintf (_T("Batch: (\'%s\', \'%s\', \'%s\') hFile = %x\n"),
|
||||
|
@ -251,6 +251,9 @@ BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param)
|
|||
|
||||
n->prev = bc;
|
||||
bc = n;
|
||||
bc->In[0] = _T('\0');
|
||||
bc->Out[0] = _T('\0');
|
||||
bc->Err[0] = _T('\0');
|
||||
}
|
||||
else if (bc->hBatchFile != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
|
@ -261,6 +264,7 @@ BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param)
|
|||
}
|
||||
|
||||
bc->hBatchFile = hFile;
|
||||
SetFilePointer (bc->hBatchFile, 0, NULL, FILE_BEGIN);
|
||||
bc->bEcho = bEcho; /* Preserve echo across batch calls */
|
||||
bc->shiftlevel = 0;
|
||||
|
||||
|
@ -276,6 +280,18 @@ BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
VOID AddBatchRedirection(TCHAR * ifn, TCHAR * ofn, TCHAR * efn)
|
||||
{
|
||||
if(!bc)
|
||||
return;
|
||||
if(_tcslen(ifn))
|
||||
_tcscpy(bc->In,ifn);
|
||||
if(_tcslen(ofn))
|
||||
_tcscpy(bc->Out,ofn);
|
||||
if(_tcslen(efn))
|
||||
_tcscpy(bc->Err,efn);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Read and return the next executable line form the current batch file
|
||||
|
@ -405,7 +421,6 @@ LPTSTR ReadBatchLine (LPBOOL bLocalEcho)
|
|||
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
DebugPrintf (_T("ReadBatchLine(): textline: \'%s\'\n"), textline);
|
||||
#endif
|
||||
|
|
|
@ -18,6 +18,9 @@ typedef struct tagBATCHCONTEXT
|
|||
INT shiftlevel;
|
||||
BOOL bEcho; /* Preserve echo flag across batch calls */
|
||||
HANDLE hFind; /* Preserve find handle when doing a for */
|
||||
TCHAR In[MAX_PATH];
|
||||
TCHAR Out[MAX_PATH];
|
||||
TCHAR Err[MAX_PATH];
|
||||
TCHAR forvar;
|
||||
} BATCH_CONTEXT, *LPBATCH_CONTEXT;
|
||||
|
||||
|
@ -39,5 +42,6 @@ LPTSTR BatchParams (LPTSTR, LPTSTR);
|
|||
VOID ExitBatch (LPTSTR);
|
||||
BOOL Batch (LPTSTR, LPTSTR, LPTSTR);
|
||||
LPTSTR ReadBatchLine (LPBOOL);
|
||||
VOID AddBatchRedirection(TCHAR *, TCHAR *, TCHAR *);
|
||||
|
||||
#endif /* _BATCH_H_INCLUDED_ */
|
||||
|
|
|
@ -72,8 +72,20 @@ INT cmd_call (LPTSTR cmd, LPTSTR param)
|
|||
bc->shiftlevel = 0;
|
||||
bc->forvar = 0; /* HBP004 */
|
||||
bc->forproto = NULL; /* HBP004 */
|
||||
|
||||
ParseCommandLine (param);
|
||||
if (bc->prev)
|
||||
{
|
||||
_tcscpy(bc->In, bc->prev->In);
|
||||
_tcscpy(bc->Out, bc->prev->Out);
|
||||
_tcscpy(bc->Err, bc->prev->Err);
|
||||
}
|
||||
else
|
||||
{
|
||||
bc->In[0] = _T('\0');
|
||||
bc->Out[0] = _T('\0');
|
||||
bc->Err[0] = _T('\0');
|
||||
}
|
||||
|
||||
|
||||
/* Wasn't a batch file so remove conext */
|
||||
if (bc->hBatchFile == INVALID_HANDLE_VALUE)
|
||||
|
|
|
@ -603,7 +603,7 @@ VOID ParseCommandLine (LPTSTR cmd)
|
|||
INT nRedirFlags = 0;
|
||||
INT Length;
|
||||
UINT Attributes;
|
||||
|
||||
BOOL bNewBatch = TRUE;
|
||||
HANDLE hOldConIn;
|
||||
HANDLE hOldConOut;
|
||||
HANDLE hOldConErr;
|
||||
|
@ -656,6 +656,20 @@ VOID ParseCommandLine (LPTSTR cmd)
|
|||
;
|
||||
_tcscpy (err, t);
|
||||
|
||||
if(bc && !_tcslen (in) && _tcslen (bc->In))
|
||||
_tcscpy(in, bc->In);
|
||||
if(bc && !out[0] && _tcslen(bc->Out))
|
||||
{
|
||||
nRedirFlags |= OUTPUT_APPEND;
|
||||
_tcscpy(out, bc->Out);
|
||||
}
|
||||
if(bc && !_tcslen (err) && _tcslen (bc->Err))
|
||||
{
|
||||
nRedirFlags |= ERROR_APPEND;
|
||||
_tcscpy(err, bc->Err);
|
||||
}
|
||||
|
||||
|
||||
/* Set up the initial conditions ... */
|
||||
/* preserve STDIN, STDOUT and STDERR handles */
|
||||
hOldConIn = GetStdHandle (STD_INPUT_HANDLE);
|
||||
|
@ -675,7 +689,7 @@ VOID ParseCommandLine (LPTSTR cmd)
|
|||
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;
|
||||
|
@ -766,7 +780,7 @@ VOID ParseCommandLine (LPTSTR cmd)
|
|||
/* 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_WRITE, &sa,
|
||||
(nRedirFlags & OUTPUT_APPEND) ? OPEN_ALWAYS : CREATE_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
|
||||
|
@ -782,7 +796,7 @@ VOID ParseCommandLine (LPTSTR cmd)
|
|||
}
|
||||
|
||||
out[size]=_T('\0');
|
||||
hFile = CreateFile (out, GENERIC_WRITE, FILE_SHARE_READ, &sa,
|
||||
hFile = CreateFile (out, GENERIC_WRITE, FILE_SHARE_WRITE, &sa,
|
||||
(nRedirFlags & OUTPUT_APPEND) ? OPEN_ALWAYS : CREATE_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
|
||||
|
@ -884,12 +898,17 @@ VOID ParseCommandLine (LPTSTR cmd)
|
|||
CloseHandle (hErr);
|
||||
hOldConErr = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
if(bc)
|
||||
bNewBatch = FALSE;
|
||||
#endif
|
||||
|
||||
/* process final command */
|
||||
DoCommand (s);
|
||||
|
||||
#ifdef FEATURE_REDIRECTION
|
||||
if(bNewBatch && bc)
|
||||
AddBatchRedirection(in, out, err);
|
||||
/* close old stdin file */
|
||||
#if 0 /* buggy implementation */
|
||||
SetStdHandle (STD_INPUT_HANDLE, hOldConIn);
|
||||
|
|
|
@ -141,6 +141,10 @@ INT cmd_for (LPTSTR cmd, LPTSTR param)
|
|||
bc->bEcho = bc->prev->bEcho;
|
||||
else
|
||||
bc->bEcho = bEcho;
|
||||
bc->In[0] = _T('\0');
|
||||
bc->Out[0] = _T('\0');
|
||||
bc->Err[0] = _T('\0');
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue