[vim/vim] Running `:!program` from `VimEnter` sends input to the program (#8591)

53 views
Skip to first unread message

xaizek

unread,
Jul 19, 2021, 10:45:43 AM7/19/21
to vim/vim, Subscribed

Describe the bug

Executing a command with :! from VimEnter auto-command sends input to that process.

To Reproduce

Make your .vimrc look like this:

au VimEnter * !cat > wtf

And just start vim (use Ctrl+D to finish cat).

You'll see output like this:

^[[2;2R^[[3;1R^[[>41;367;0c^[]10;rgb:ffff/ffff/ffff^G^[]11;rgb:0808/0808/0808^G

and wtf file in current directory containing the same:

00000000  1b 5b 32 3b 32 52 1b 5b  33 3b 31 52 1b 5b 3e 34  |.[2;2R.[3;1R.[>4|
00000010  31 3b 33 36 37 3b 30 63  1b 5d 31 30 3b 72 67 62  |1;367;0c.]10;rgb|
00000020  3a 66 66 66 66 2f 66 66  66 66 2f 66 66 66 66 07  |:ffff/ffff/ffff.|
00000030  1b 5d 31 31 3b 72 67 62  3a 30 38 30 38 2f 30 38  |.]11;rgb:0808/08|
00000040  30 38 2f 30 38 30 38 07  3a                       |08/0808.:|
00000049

Expected behavior

No unexpected output on the screen and empty wtf file.

Environment (please complete the following information):

  • Vim version: 8.2.2876
  • OS: Slackware 14.2
  • Terminal: xterm

Additional context

This looks a lot like control sequences, although I'm not sure whether they are coming from Vim itself or that's a terminal responding to some query from Vim. I suspect the latter.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

Bram Moolenaar

unread,
Jul 19, 2021, 11:48:54 AM7/19/21
to vim/vim, Subscribed


> **Describe the bug**

>
> Executing a command with `:!` from VimEnter auto-command sends input to that process.
>
> **To Reproduce**

>
> Make your `.vimrc` look like this:
> ```vim

> au VimEnter * !cat > wtf
> ```
> And just start `vim` (use <kbd>Ctrl+D</kbd> to finish `cat`).

>
> You'll see output like this:
>
> ```
> ^[[2;2R^[[3;1R^[[>41;367;0c^[]10;rgb:ffff/ffff/ffff^G^[]11;rgb:0808/0808/0808^G
> ```
>
> and `wtf` file in current directory containing the same:
> ```
> 00000000 1b 5b 32 3b 32 52 1b 5b 33 3b 31 52 1b 5b 3e 34 |.[2;2R.[3;1R.[>4|
> 00000010 31 3b 33 36 37 3b 30 63 1b 5d 31 30 3b 72 67 62 |1;367;0c.]10;rgb|
> 00000020 3a 66 66 66 66 2f 66 66 66 66 2f 66 66 66 66 07 |:ffff/ffff/ffff.|
> 00000030 1b 5d 31 31 3b 72 67 62 3a 30 38 30 38 2f 30 38 |.]11;rgb:0808/08|
> 00000040 30 38 2f 30 38 30 38 07 3a |08/0808.:|
> 00000049
> ```
>
> **Expected behavior**

>
> No unexpected output on the screen and empty `wtf` file.
>
> **Environment (please complete the following information):**
> - Vim version: 8.2.2876
> - OS: Slackware 14.2
> - Terminal: xterm
>
> **Additional context**

>
> This looks a lot like control sequences, although I'm not sure whether
> they are coming from Vim itself or that's a terminal responding to
> some query from Vim. I suspect the latter.

Yes, Vim request status from the terminal, and since there is no side
channel these are mixed with keyboard input.

Vim does try to read the escape codes before starting the program, but
this is timing sensitive.

A simple way would be to not invoke the program directly from VimEnter,
but using a timer to run it a tiny bit later.

Hmm, perhaps we could have an autocommand event that is triggered when
the codes that are expected have been received. Problem is though that
some requests may be unanswered, and then it would never trigger.


--
hundred-and-one symptoms of being an internet addict:
182. You may not know what is happening in the world, but you know
every bit of net-gossip there is.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Gary Johnson

unread,
Jul 19, 2021, 12:20:58 PM7/19/21
to reply+ACY5DGCDZAABVNWFMC...@reply.github.com, vim...@googlegroups.com
On 2021-07-19, Bram Moolenaar wrote:

> A simple way would be to not invoke the program directly from VimEnter,
> but using a timer to run it a tiny bit later.
>
> Hmm, perhaps we could have an autocommand event that is triggered when
> the codes that are expected have been received. Problem is though that
> some requests may be unanswered, and then it would never trigger.

You could use a timeout to fix that. A few seconds should be
sufficient. If a user's terminal never responds and the user gets
tired of waiting that long, then they don't need the autocommand
anyway.

The timeout should be settable, and there should be a way to
determine whether the autocommand was triggered by the terminal
responses or by the timer expiring. Some v: variable, perhaps.
Maybe just check for the presence of all the expected responses.

Regards,
Gary

vim-dev ML

unread,
Jul 19, 2021, 12:21:17 PM7/19/21
to vim/vim, vim-dev ML, Your activity
Reply all
Reply to author
Forward
0 new messages