diff options
author | Berke Viktor <berkeviktor@aol.com> | 2011-11-27 11:05:38 +0100 |
---|---|---|
committer | Berke Viktor <berkeviktor@aol.com> | 2011-11-27 11:05:38 +0100 |
commit | 837557e9c73b0b266d06bdf2ca7428ecdbc9f35c (patch) | |
tree | f8630c6e13e5501cb30a34c7f6448824dba6c840 | |
parent | 5d50ec01cb03122cdabb5fd2dace903e50c565e8 (diff) |
make exec display as nice as possible
-rw-r--r-- | plugins/exec/exec.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/plugins/exec/exec.c b/plugins/exec/exec.c index 71adf15c..9d400e10 100644 --- a/plugins/exec/exec.c +++ b/plugins/exec/exec.c @@ -57,7 +57,7 @@ run_command (char *word[], char *word_eol[], void *userdata) strcpy (commandLine, "cmd.exe /c "); 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 (&pInfo, sizeof (pInfo)); @@ -67,7 +67,7 @@ run_command (char *word[], char *word_eol[], void *userdata) sInfo.hStdOutput = writePipe; sInfo.hStdError = writePipe; - CreateProcess (0, commandLine, 0, 0, TRUE, NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW, 0, 0, &sInfo, &pInfo); + CreateProcess (0, commandLine, 0, 0, TRUE, NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW, 0, 0, &sInfo, &pInfo); CloseHandle (writePipe); start = time (0); @@ -77,17 +77,23 @@ run_command (char *word[], char *word_eol[], void *userdata) { if (ReadFile (readPipe, buffer, sizeof (buffer) - 1, &dwRead, NULL) && dwRead != 0 ) { + /* avoid garbage */ 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); } } 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); |