Skip to content

External commands do not always run in correct directory or environment #9741

@Tridecatrix

Description

@Tridecatrix

Describe the bug
External commands in Windows do not run from current directory (instead running from /c/Program Files/VSCodium), and when using Remote WSL or Remote SSH do not run in correct environment (they still run in Windows CMD). Applies to both :r !cmd and :'<,'> !cmd.

To Reproduce
Steps to reproduce the behavior:

In local Windows environment:

  1. Open a folder in VSCodium
  2. Open a file in that folder
  3. Run :r !dir
  4. Output printed to file indicates " Directory of C:\Program Files\VSCodium", and so the command was run from wrong directory.

In Remote WSL or SSH:

  1. Open a Remote WSL session, or a Remote SSH to a Linux device.
  2. Run :r !ls. Vim output in console reports error executing command and "ls is not recognized as an internal or external command", indicating command was run in Windows and not Linux.

Same behavior occurs if one highlights some text, goes into visual mode with V and then tries !dir.

Expected behavior
Commands are run in the correct environment and same directory as current file, which is the behavior in Vim.

Screenshots
If applicable, add screenshots to help explain your problem.
If remapping-related, please attach log output: https://github.com/VSCodeVim/Vim#debugging-remappings.

Output of :r dir when running in local Windows:
Image

Error message from running in VSCode WSL:
Image

Environment (please complete the following information):

  • Extension (VsCodeVim) version: 1.30.1
    • Open Remote SSH by Jeanp ver 0.049
    • Open Remote WSL by Jeanp ver 0.0.5, using WSL version 2.5.10.0
  • VSCode version: 1.87
  • OS: Windows 11 Enterprise

Additional context
This is an extension of the long-standing issue reported here, which indicates that the read command doesn't use correct environment/directory for files either: #6678.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions