Windows 10 SSH from terminal (WP-CLI database access issues)

I was trying to use WP-CLI from my terminal… using the new Windows Terminal app and the Linux Subsystem that is finally available and totally rocks. But from my normal command line commands like wp db prefix don’t work because the command can’t connect to the DB that’s in the local container.

So I researched a little and found the feature where you can launch SSH from the Local UI. This lauches the crummy old school Windows Command Prompt (cmd.exe) though and I can’t run any custom commands. For example I have this activated in a plugin:

function kia_test_cli(){
	if ( defined( 'WP_CLI' ) && WP_CLI ) {
		WP_CLI::add_command( 'test', 'kia_test_cli_command' );
	}
}
add_action( 'plugins_loaded', 'kia_test_cli' );


function kia_test_cli_command() {
	WP_CLI::runcommand( 'db prefix' );
}

But when I run wp test in the cmd.exe console I get “Could not open input file C:\Program” It’s not clear exactly what file this is referencing but I’m guessing it’s stuck on windows naming system as “C:\Program Files” has a space in it.

So I either

  1. need the ability to change the terminal that “Open site shell” launches (Which would be a great option in Local since it’s a dev tool and even in windows there are finally some good options for terminals). Just found this Ability to change Windows SSH Client post so gonna try that next.

or

  1. need to know how to SSH into the container from another terminal. How does one find the IP address for the container.

or

  1. Advice on how to set up: https://github.com/bigwing/local-wp-cli which looks promising but I was unsure which the readme references.

Hi Kathy,

Sorry for the trouble!

The issue with wp db is a bug with WP-CLI itself that our team has created a patch for. See Unable to access database

Do the other commands like wp option get work?

Hi Clay. Yes, other commands do seem to work. Thanks for the info, glad to know where the source of the issue is. The PR looks like it was merged in January. Has it been released yet?

Still, would be great if there was an option to choose which shell. As I mentioned, there are now way better options in Windows than cmd.exe.

The PR has been merged and included in WP-CLI 2.4.1. However, WP-CLI’s default download is still pointing to version 2.4.0.

Regardless, we’re planning on pulling WP-CLI 2.4.1 in an upcoming sprint and making the necessary adjustments to take advantage of the PR.


I totally agree. We have a feature request here: https://feedback.localwp.com/feature-requests/p/change-default-shellterminal-on-windows

Feel free to vote it up! :grin:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.