Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

job_start behaves differently than running the command in command line #4529

Closed
ipod825 opened this issue Jun 13, 2019 · 8 comments
Closed

Comments

@ipod825
Copy link

ipod825 commented Jun 13, 2019

Describe the bug
running rm command with job_start behaves differently than running it in the command line.

To Reproduce
First run in command line:

mkdir foo; cd foo; touch a; chmod u-w a;vim --clean

:call job_start('rm a',{'out_cb':{j,d->append(line('.',d))}})
:!ls

Actual behaviour

The file a is deleted without any output being append to the current buffer.

Expected behavior
Because the file a is write protected, rm prompts rm: remove write-protected regular empty file 'a'? in the command line, while it didn't trigger the on_stdout with this prompt.

Environment (please complete the following information):

  • Vim version: 8.1.1467
  • OS: [5.1.7-arch1-1-ARCH
@ipod825
Copy link
Author

ipod825 commented Jun 13, 2019

Same issue in neovim

@k-takata
Copy link
Member

The prompt will be output to stderr, not stdout.

@ipod825
Copy link
Author

ipod825 commented Jun 13, 2019

@k-takata
Changing the command to

:call job_start('rm a',{'err_cb':{j,d->append(line('.',d))}})

Still no output append to the buffer and the file is deleted silently.

@k-takata
Copy link
Member

Maybe because stdin is redirected to /dev/null?
The following command deletes the file a silently:

$ rm a < /dev/null

@ipod825
Copy link
Author

ipod825 commented Jun 13, 2019

That's possible. Thought based on the document:

"in_io": "pipe"         stdin is connected to the channel (default)

stdin shouldn't be redirected by default.

Explicitly running
:call job_start('rm a',{'out_cb':{j,d->append(line('.',d))}, 'err_cb':{j,d->append(line('.',d))} , 'in_io':'pipe'})
still not working.

@blueyed
Copy link

blueyed commented Jun 13, 2019

Using 'pty': 1 makes it work on Neovim - it outputs to stdout then.

@mattn
Copy link
Member

mattn commented Jun 13, 2019

You must specify ["rm", "a"] for the first argument instead of "rm a".

@chrisbra
Copy link
Member

chrisbra commented Jun 14, 2019

This is not a bug in Vim. The error message from rm that you see, is only issued, if rm is connected to a tty. See remove.c from coreutils:

https://github.com/coreutils/coreutils/blob/0251229bfd9617e8a35cf9dd7d338d63fff74a0c/src/remove.c#L210-L216

  if (!x->ignore_missing_files
      && ((x->interactive == RMI_ALWAYS) || x->stdin_tty)
      && dirent_type != DT_LNK)
    {
      write_protected = write_protected_non_symlink (fd_cwd, filename, sbuf);
      wp_errno = errno;
}

So only when the stdin is a tty (or the -i option has been used), write_protected will be set and only if it is set, the prompt will be shown later.

You can see the same behaviour when using ssh, compare this:

0 141896 chrisbra@debian ~/temp/foo % touch a && chmod a-w a && ssh  localhost rm $PWD/a
chrisbra@localhost's password:
0 141897 chrisbra@debian ~/temp/foo % ls -l
total 0
0 141898 chrisbra@debian ~/temp/foo % touch a && chmod a-w a && ssh -t  localhost rm $PWD/a
chrisbra@localhost's password:
rm: remove write-protected regular empty file '/home/chrisbra/temp/foo/a'? n
Connection to localhost closed.

You can force this in Vim using the pty argument of job_start().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants