8000 Fix group alias execution on Windows by passing $env to proc_open_compat by Copilot · Pull Request #6221 · wp-cli/wp-cli · GitHub
[go: up one dir, main page]

Skip to content

Fix group alias execution on Windows by passing $env to proc_open_compat#6221

Closed
Copilot wants to merge 3 commits intomainfrom
copilot/fix-ssh-error-alias-groups
Closed

Fix group alias execution on Windows by passing $env to proc_open_compat#6221
Copilot wants to merge 3 commits intomainfrom
copilot/fix-ssh-error-alias-groups

Conversation

Copy link
Contributor
Copilot AI commented Feb 2, 2026

Group aliases with SSH configurations fail on Windows with "ssh is not recognized as an internal or external command". Single aliases work correctly.

Root Cause

run_alias_group() spawns child processes with Unix-style environment variable syntax:

$full_command = "WP_CLI_CONFIG_PATH={$config_path} {$php_bin} {$script_path} {$alias} ...";

Without the $env parameter, proc_open_compat() cannot invoke _proc_open_compat_win_env() to extract and separate environment variables on Windows. Child processes fail to load the config file, breaking SSH alias resolution.

Changes

php/WP_CLI/Runner.php

  • Initialize $env = null before proc_open_compat() call
  • Pass $env as 5th parameter to enable Windows environment variable extraction
// Before
$proc = Utils\proc_open_compat( $full_command, [ STDIN, STDOUT, STDERR ], $pipes );

// After  
$env = null;
$proc = Utils\proc_open_compat( $full_command, [ STDIN, STDOUT, STDERR ], $pipes, null, $env );

The existing _proc_open_compat_win_env() function extracts WP_CLI_CONFIG_PATH=/path from the command string and populates $env['WP_CLI_CONFIG_PATH'], allowing Windows to properly set the environment for child processes.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • example.com
    • Triggering command: /usr/bin/php php vendor/bin/phpunit --color=always --bootstrap ./vendor/wp-cli/wp-cli-tests/tests/bootstrap.php (dns block)
  • nosuchhost_asdf_asdf_asdf.com
    • Triggering command: /usr/bin/php php vendor/bin/phpunit --color=always --bootstrap ./vendor/wp-cli/wp-cli-tests/tests/bootstrap.php (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<i 8000 ssue_title>SSH error when using alias groups in remote commands</issue_title>
<issue_description>## Bug Report

Describe the current, buggy behavior

When I run a command against multiple aliases using the group alias @clients, I get the following error:
ssh is not recognized as an internal or external command, operable program or batch file. (see attachment)
error

The weird thing though is that when I run a command with just an regular alias, like wp @client_name core update, everything works fine. Besides, everything is just set up accordingly to the documentation in the config.yml file.

Describe what you expect as the correct outcome

The command should just run against all the listed aliased in the group @clients.

@clients:
  - @client1
  - @client2
  - @client3

(Paste the output of "wp cli info" into this box)

Shell:  C:\Program Files\Git\usr\bin\bash.exe
PHP binary:     C:\xampp\php\php.exe
PHP version:    7.3.2
php.ini used:   C:\xampp\php\php.ini
WP-CLI root dir:        phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:      phar://wp-cli.phar/vendor
WP_CLI phar path:       C:\Users\Pieter
WP-CLI packages dir:
WP-CLI global config:   C:\Users\Pieter/.wp-cli/config.yml
WP-CLI project config:
WP-CLI version: 2.4.0```

</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@github-actions github-actions bot added bug command:cli Related to 'cli' command command:cli-alias Related to 'cli alias' command labels Feb 2, 2026
@codecov
Copy link
codecov bot commented Feb 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix SSH error when using alias groups in remote commands Fix group alias execution on Windows by passing $env to proc_open_compat Feb 2, 2026
Copilot AI requested a review from swissspidy February 2, 2026 03:50
@swissspidy swissspidy marked this pull request as ready for review February 2, 2026 04:01
@swissspidy swissspidy requested a review from a team as a code owner February 2, 2026 04:01
Copilot AI review requested due to automatic review settings February 2, 2026 04:01

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

Copy link
Contributor
Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +1333 to +1334
$env = null;
$proc = Utils\proc_open_compat( $full_command, [ STDIN, STDOUT, STDERR ], $pipes, null, $env );
Copy link
Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing $env initialized to null into Utils\proc_open_compat() appears to be a no-op: proc_open_compat() already calls _proc_open_compat_win_env( $cmd, $env ) on Windows even when $env is omitted/defaults to null (php/utils.php:1831-1837). Also, the sequential branch below still uses the 3-arg call, so if the PR description’s root cause is accurate, group aliases would still fail when WP_CLI_ALIAS_GROUPS_PARALLEL is not set. Please either adjust the real root cause (e.g., command/env construction) or apply an effective fix consistently to both branches (and/or proc_open_compat() itself).

Suggested change
$env = null;
$proc = Utils\proc_open_compat( $full_command, [ STDIN, STDOUT, STDERR ], $pipes, null, $env );
$proc = Utils\proc_open_compat( $full_command, [ STDIN, STDOUT, STDERR ], $pipes );

Copilot uses AI. Check for mistakes.
@swissspidy
Copy link
Member

Already addressed in #5689

@swissspidy swissspidy closed this Mar 10, 2026
@swissspidy swissspidy deleted the copilot/fix-ssh-error-alias-groups branch March 10, 2026 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug command:cli Related to 'cli' command command:cli-alias Related to 'cli alias' command os:windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SSH error when using alias groups in remote commands

3 participants

0