WP_CLI\Utils

_proc_open_compat_win_env()WP-CLI 1.0

For use by proc_open_compat() Separated out for ease of testing. Windows only. Turns *nix-like ENV_VAR=blah command environment variable prefixes into stripped cmd with prefixed environment variables added to passed in environment array.

Internal function — this function is designed to be used by the kernel itself. It is 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.8.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;
}