WP_CLI\Utils

_proc_open_compat_win_env()WP-CLI 1.0

Turns *nix-like ENV_VAR=blah command environment variable prefixes into stripped cmd with prefixed environment variables added to passed in environment array.

This is an internal function for using it by WP core itself. It's not recommended to use this function in your code.

No Hooks.

Return

String. Command stripped of any environment variable settings.

Usage

_proc_open_compat_win_env( $cmd, $env );
$cmd(string) (required)
Command to execute.
$env (required) (passed by reference — &)
-

_proc_open_compat_win_env() code WP-CLI 2.7.0-alpha

function _proc_open_compat_win_env( $cmd, &$env ) {
	if ( false !== strpos( $cmd, '=' ) ) {
		while ( preg_match( '/^([A-Za-z_][A-Za-z0-9_]*)=("[^"]*"|[^ ]*) /', $cmd, $matches ) ) {
			$cmd = substr( $cmd, strlen( $matches[0] ) );
			if ( null === $env ) {
				$env = [];
			}
			$env[ $matches[1] ] = isset( $matches[2][0] ) && '"' === $matches[2][0] ? substr( $matches[2], 1, -1 ) : $matches[2];
		}
	}
	return $cmd;
}