I am getting some unexpected behavior when trying to run the zip
shell command using Vim's job_start()
.
As an example, suppose I have two images (im1.png
and im2.jpg
) in the directory /home/username/test_dir/
and I want to zip them. This shell command will zip the files:
cd /home/username/test_dir/ && zip ims.zip im1.png im2.jpg
Next, I make a simple vimrc file (/home/username/test_dir/simple_vimrc
) containing only a function that runs that command via job_start()
:
function! Test()
let job = job_start(['/bin/sh', '-c', 'cd /home/username/test_dir/ && zip ims.zip im1.png im2.jpg'])
endfunction
Then I open Vim as
vim --clean -u /home/username/test_dir/simple_vimrc
If I run :call Test()
, the zip
command does not seem to work - instead of producing a zip file it just produces an empty file with a random name. But here are some interesting observations:
Adding the job option
{'err_io': 'buffer'}
to thejob_start()
command makes it work. But it fails with all other'err_io'
options ('out'
,'null'
,'pipe'
, and'file'
). This seems strange because no error is produced anyway.I added the job options
'out_cb'
,'err_cb'
,'close_cb'
, and'exit_cb'
to thejob_start()
command with blank callback functions (I tested each option individually). Strangely, all options except'exit_cb'
made the command work.The command works if I run the
let job = ...
command directly in Vim's colon command line.I tried all cases above by replacing the
zip
command with:- a
pdflatex
command to compile a simple Latex file (succeeded/failed in all the same cases as thezip
command) - a
gcc
command to compile a simple C file (succeeded in all cases) - a
python
command to run a simple Python file (succeeded in all cases)
- a
I'm confused as to why job_start()
successfully runs the command only in these certain cases. Is this expected behavior or a bug I should report?