Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

always read stdout and stderr from forked commands #11

Merged
merged 1 commit into from

1 participant

@dscho
Owner

When not doing so such output would be forwarded to a program using
this plugin. Normally in Windows GUI programs there is no console so
this did not disturb anyone.

Far Manager is a console program that also uses shell extensions for
which this was reported.

Fix this by always reading the output into a strbuf. Since we are
tracing the ouput later on anyway the output does not get lost.

Signed-off-by: Heiko Voigt hvoigt@hvoigt.net

Heiko Voigt always read stdout and stderr from forked commands
When not doing so such output would be forwarded to a program using
this plugin. Normally in Windows GUI programs there is no console so
this did not disturb anyone.

Far Manager is a console program that also uses shell extensions for
which this was reported.

Fix this by always reading the output into a strbuf. Since we are
tracing the ouput later on anyway the output does not get lost.

Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
f743394
@dscho dscho merged commit a6c3759 into from
@dscho dscho deleted the branch
@dscho
Owner

@hvoigt this has caused substantially more problems than it solved.

Now I sat down and wasted half an hour to fix this issue, and even downloaded FarManager to test. However, it seems that the shell extensions are not even shown by default! How do I see the problem you tried to address???

@dscho
Owner

So FarManager is a 32-bit application and does not pick up the 64-bit context menu. That's why I did not see it in the EMenu.

For the record, there could have been a much more detailed commit message that would have saved me a lot of grief, something along the lines: in FarManager, hit F11, choose EMenu, then GUI, to open an Explorer context menu for the current item (for 32-bit FarManager, only 32-bit shell extensions are heeded). Hopefully next time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 13, 2013
  1. always read stdout and stderr from forked commands

    Heiko Voigt authored
    When not doing so such output would be forwarded to a program using
    this plugin. Normally in Windows GUI programs there is no console so
    this did not disturb anyone.
    
    Far Manager is a console program that also uses shell extensions for
    which this was reported.
    
    Fix this by always reading the output into a strbuf. Since we are
    tracing the ouput later on anyway the output does not get lost.
    
    Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
This page is out of date. Refresh to see the latest.
Showing with 32 additions and 37 deletions.
  1. +32 −37 common/exec.c
View
69 common/exec.c
@@ -46,6 +46,12 @@ int exec_program_v(const char *working_directory,
int status = 0;
int ret;
+ struct strbuf strout = STRBUF_INIT, strerr = STRBUF_INIT;
+ if (!output)
+ output = &strout;
+ if (!error_output)
+ error_output = &strerr;
+
reporter *debug = QUIETMODE & flags ? _debug_git : _debug_git_mbox;
if (!git_path()) {
@@ -53,27 +59,23 @@ int exec_program_v(const char *working_directory,
return -1;
}
- if (output) {
- if (pipe(fdout) < 0) {
- return -ERR_RUN_COMMAND_PIPE;
- }
- s1 = dup(1);
- dup2(fdout[1], 1);
-
- flags |= WAITMODE;
+ if (pipe(fdout) < 0) {
+ return -ERR_RUN_COMMAND_PIPE;
}
+ s1 = dup(1);
+ dup2(fdout[1], 1);
- if (error_output) {
- if (pipe(fderr) < 0) {
- if (output)
- close_pair(fdout);
- return -ERR_RUN_COMMAND_PIPE;
- }
- s2 = dup(2);
- dup2(fderr[1], 2);
+ flags |= WAITMODE;
- flags |= WAITMODE;
+ if (pipe(fderr) < 0) {
+ if (output)
+ close_pair(fdout);
+ return -ERR_RUN_COMMAND_PIPE;
}
+ s2 = dup(2);
+ dup2(fderr[1], 2);
+
+ flags |= WAITMODE;
pid = fork_process(argv[0], argv, working_directory);
@@ -83,17 +85,13 @@ int exec_program_v(const char *working_directory,
dup2(s2, 2), close(s2);
if (pid < 0) {
- if (output)
- close_pair(fdout);
- if (error_output)
- close_pair(fderr);
+ close_pair(fdout);
+ close_pair(fderr);
return -ERR_RUN_COMMAND_FORK;
}
- if (output)
- close(fdout[1]);
- if (error_output)
- close(fderr[1]);
+ close(fdout[1]);
+ close(fderr[1]);
if (WAITMODE & flags) {
ret = wait_for_process(pid, MAX_PROCESSING_TIME,
@@ -109,15 +107,11 @@ int exec_program_v(const char *working_directory,
status = -1;
}
- if (output) {
- strbuf_read(output, fdout[0], 0);
- debug_git("STDOUT:\r\n%s\r\n*** end of STDOUT ***\r\n", output->buf);
- }
+ strbuf_read(output, fdout[0], 0);
+ debug_git("STDOUT:\r\n%s\r\n*** end of STDOUT ***\r\n", output->buf);
- if (error_output) {
- strbuf_read(error_output, fderr[0], 0);
- debug_git("STDERR:\r\n%s\r\n*** end of STDERR ***\r\n", error_output->buf);
- }
+ strbuf_read(error_output, fderr[0], 0);
+ debug_git("STDERR:\r\n%s\r\n*** end of STDERR ***\r\n", error_output->buf);
} else {
status = -ERR_RUN_COMMAND_WAITPID_NOEXIT;
debug_git("[ERROR] process timed out; "
@@ -127,10 +121,11 @@ int exec_program_v(const char *working_directory,
}
close_process(pid);
- if (output)
- close(fdout[0]);
- if (error_output)
- close(fderr[0]);
+ close(fdout[0]);
+ close(fderr[0]);
+
+ strbuf_release(&strerr);
+ strbuf_release(&strout);
return status;
}
Something went wrong with that request. Please try again.