pydave/AsyncCommand — Issue #3: Subtle shell redirection bug
Author: moorec
Created: 2011-10-20 18:53:01+00:00
State: open

I just started upgrading to 3.1 and have been working with a small function to run Gimple Software's FlexeLint. In our organization, we are supporting both Vim and Emacs--which leads us to moving shared functionality into shell scripts when beneficial. In this case, we have a shell script that takes a numeric, optional last argument.

From our plugin:

function! util#LintImpl(client, target, options)
let cmd = '/u/asdf/lint_build.sh '.a:client.' '.a:target.' '.a:options
" echo 'Executing <'.cmd.'> asynchronously.'
let env = asynchandler#quickfix(&errorformat, 'lint results')
call asynccommand#run(cmd, env)
endfunction

From ./autoload/asynccommand.vim:

let shellredir = &shellredir
if match( shellredir, '%s') == -1
" ensure shellredir has a %s so printf works
let shellredir .= '%s'
endif

" Grab output and error in case there's something we should see
let tool_cmd = a:command . printf(shellredir, temp_file)

The problem is that the shell redirection characters are appended to the user's shell command (without a space of separation). For example, I wanted to run "/u/asdf/lint_build.sh X Y 1" which results in tool_cmd "/u/asdf/lint_build.sh X Y 1>%s 2>&1" (where %s is the temp file name). The command that executes now redirects stdout unexpectedly!

Here's the patch to throw a space in between:
60c60
< let shellredir = &shellredir
---
> let shellredir = ' '.&shellredir

Thanks,
Chad Moore