Skip to content

Commit

Permalink
Use the absolute PowerShell path (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyBelym committed Dec 11, 2019
1 parent b981526 commit 7e8baac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/utils/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import nanoid from 'nanoid';
import promisify from './promisify';
import BINARIES from '../binaries';
import flattenWhitespace from './flatten-whitespace';
import getEnvironmentVariable from './get-environment-variable';
import { NativeBinaryHasFailedError } from '../errors';


Expand All @@ -17,7 +18,9 @@ const EXIT_CODE_REGEXP = /Exit code: (-?\d+)/;
const OPEN_PATH = '/usr/bin/open';
const TEMP_PIPE_NAME = seed => `testcafe-browser-tools-fifo-${seed}`;

const POWERSHELL_BINARY = 'powershell.exe';
const WINDOWS_DIR = getEnvironmentVariable('SystemRoot') || 'C:\\Windows';
const POWERSHELL_DIR = path.join(WINDOWS_DIR, 'System32\\WindowsPowerShell\\v1.0');
const POWERSHELL_BINARY = path.join(POWERSHELL_DIR, 'powershell.exe');
const POWERSHELL_ARGS = ['-NoLogo', '-NonInteractive', '-Command'];

const POWERSHELL_COMMAND_WRAPPER = command => flattenWhitespace `
Expand Down Expand Up @@ -130,5 +133,5 @@ export async function execPowershell (command) {

// NOTE: We have to ignore stdin due to a problem with PowerShell 2.0
// See https://stackoverflow.com/a/9157170/11818061 for details.
return execa(POWERSHELL_BINARY, [...POWERSHELL_ARGS, `"${wrappedCommand}"`], { stdin: 'ignore', shell: true });
return execa(POWERSHELL_BINARY, [...POWERSHELL_ARGS, wrappedCommand], { stdin: 'ignore' });
}
9 changes: 9 additions & 0 deletions src/utils/get-environment-variable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function getEnvironmentVariableName (source) {
const names = Object.keys(process.env);

return names.find(name => name === source) || names.find(name => name.toLowerCase() === source.toLowerCase());
}

export default function (name) {
return process.env[getEnvironmentVariableName(name)];
}

0 comments on commit 7e8baac

Please sign in to comment.