mushanshitiancai / vscode-paste-image

paste image from clipboard to markdown/asciidoc directly!
MIT License
423 stars 128 forks source link

Add powershell full path for windows #13

Closed elbehery95 closed 7 years ago

elbehery95 commented 7 years ago

Exception thrown when users did not set powershell in windows environmental variables, this causes the powerscript that paste images to not work at all.

Issue#12

mushanshitiancai commented 7 years ago

I adopt your modify and add some improvement, like this:

let command = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe";
let powershellExisted = fs.existsSync(command)
if (!powershellExisted) {
    command = "powershell"
}

const powershell = spawn(command, [
    '-noprofile',
    '-noninteractive',
    '-nologo',
    '-sta',
    '-executionpolicy', 'unrestricted',
    '-windowstyle', 'hidden',
    '-file', scriptPath,
    imagePath
]);
powershell.on('error', function (e) {
    if (e.code == "ENOENT") {
        Logger.showErrorMessage(`The powershell command is not in you PATH environment variables.Please add it and retry.`);
    } else {
        Logger.showErrorMessage(e);
    }
});

detail: Paste fail when powershell not in PATH on windows · mushanshitiancai/vscode-paste-image@14a7065

Thank you for you mr very much!

elbehery95 commented 7 years ago

Great, thanks so much :)