mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-24 01:23:03 +01:00
Fix premature EOF while reading a script file when using the SHELL command inside it, found by Paul Reeves. Trying to find a compromise between MS requirements for system() call and its bad side effects on our isql.
This commit is contained in:
parent
f58ecb7e68
commit
d7f1979164
@ -3429,26 +3429,31 @@ static processing_state escape(const TEXT* cmd)
|
|||||||
#ifdef WIN_NT
|
#ifdef WIN_NT
|
||||||
// MSDN says: You must explicitly flush (using fflush or _flushall)
|
// MSDN says: You must explicitly flush (using fflush or _flushall)
|
||||||
// or close any stream before calling system.
|
// or close any stream before calling system.
|
||||||
_flushall();
|
// CVC: But that function defeats our possible several input streams opened.
|
||||||
|
//_flushall();
|
||||||
|
// Save Ofp position in case it's being used as input. See EDIT command.
|
||||||
|
fpos_t OfpPos = 0;
|
||||||
|
fgetpos(Ofp, &OfpPos);
|
||||||
|
fflush(NULL); // Flush only output buffers.
|
||||||
|
const char* emptyCmd = "%ComSpec%";
|
||||||
|
#else
|
||||||
|
const char* emptyCmd = "$SHELL";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// If no command given just spawn a shell
|
// If no command given just spawn a shell
|
||||||
|
if (!*shellcmd)
|
||||||
|
shellcmd = emptyCmd;
|
||||||
|
|
||||||
|
int rc = system(shellcmd);
|
||||||
|
|
||||||
if (!*shellcmd) {
|
|
||||||
#ifdef WIN_NT
|
#ifdef WIN_NT
|
||||||
if (system("%ComSpec%"))
|
// If we are reading from the temp file, restore the read position because
|
||||||
return FAIL;
|
// it's opened in r+ mode in this case, that's R/W.
|
||||||
#else
|
if (Ifp.indev_fpointer == Ofp)
|
||||||
if (system("$SHELL"))
|
fsetpos(Ofp, &OfpPos);
|
||||||
return FAIL;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
else {
|
return rc ? FAIL : SKIP;
|
||||||
if (system(shellcmd))
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (SKIP);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user