Skip to content

Commit 262e616

Browse files
committed
escape % to %% for all commands run on Windows
This prevents cmd.exe from misinterpreting %...% as undefined environment variables and stripping them.
1 parent 6b5c279 commit 262e616

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/Context/FeatureContext.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,10 @@ public function proc( $command, $assoc_args = [], $path = '' ): Process {
13781378
$command .= Utils\assoc_args_to_str( $assoc_args );
13791379
}
13801380

1381+
if ( Utils\is_windows() ) {
1382+
$command = str_replace( '%', '%%', $command );
1383+
}
1384+
13811385
$env = self::get_process_env_variables();
13821386

13831387
if ( Utils\is_windows() ) {
@@ -1420,6 +1424,7 @@ public function proc( $command, $assoc_args = [], $path = '' ): Process {
14201424
*/
14211425
public function background_proc( $cmd ): void {
14221426
if ( Utils\is_windows() ) {
1427+
$cmd = str_replace( '%', '%%', $cmd );
14231428
fwrite( STDERR, "DEBUG WINDOWS BG_PROC: cmd={$cmd}\n" );
14241429
// On Windows, leaving pipes open can cause hangs.
14251430
// Redirect output to files and close stdin.

0 commit comments

Comments
 (0)