make exec display as nice as possible

This commit is contained in:
Berke Viktor 2011-11-27 11:05:38 +01:00
parent 5d50ec01cb
commit 837557e9c7
1 changed files with 10 additions and 4 deletions

View File

@ -57,7 +57,7 @@ run_command (char *word[], char *word_eol[], void *userdata)
strcpy (commandLine, "cmd.exe /c "); strcpy (commandLine, "cmd.exe /c ");
strcat (commandLine, word_eol[2]); strcat (commandLine, word_eol[2]);
CreatePipe (&readPipe, &writePipe, &secattr, 0); CreatePipe (&readPipe, &writePipe, &secattr, 0); /* might be replaced with MyCreatePipeEx */
ZeroMemory (&sInfo, sizeof (sInfo)); ZeroMemory (&sInfo, sizeof (sInfo));
ZeroMemory (&pInfo, sizeof (pInfo)); ZeroMemory (&pInfo, sizeof (pInfo));
@ -77,17 +77,23 @@ run_command (char *word[], char *word_eol[], void *userdata)
{ {
if (ReadFile (readPipe, buffer, sizeof (buffer) - 1, &dwRead, NULL) && dwRead != 0 ) if (ReadFile (readPipe, buffer, sizeof (buffer) - 1, &dwRead, NULL) && dwRead != 0 )
{ {
/* avoid garbage */
buffer[dwRead] = '\0'; buffer[dwRead] = '\0';
xchat_printf (ph, "%s\n", buffer); xchat_printf (ph, "%s", buffer);
} }
} }
else
{
/* this way we'll more likely get full lines */
SleepEx (100, TRUE);
}
timeElapsed = difftime (time (0), start); timeElapsed = difftime (time (0), start);
} }
} }
if (timeElapsed >= 10) if (timeElapsed >= 10)
{ {
xchat_printf (ph, "Execution took too long, aborting.\n"); xchat_printf (ph, "Command took too much time to run, execution aborted.\n");
} }
CloseHandle (readPipe); CloseHandle (readPipe);