Skip to content

Commit

Permalink
Fixed bug where .bat files with spaces in their path couldn't be exec…
Browse files Browse the repository at this point in the history
…uted
  • Loading branch information
nils-soderman committed Mar 27, 2022
1 parent 4ede07c commit 0a6b54a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## v0.0.2
(27-03-2022)

- Fixed bug where batch files with spaces in their path could not be executed

## v0.0.1
(21-03-2022)

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Batch Runner",
"publisher": "NilsSoderman",
"description": "Execute batch file in the vscode terminal",
"version": "0.0.1",
"version": "0.0.2",
"engines": {
"vscode": "^1.64.0"
},
Expand Down Expand Up @@ -91,4 +91,4 @@
"typescript": "^4.3.2",
"vscode-test": "^1.4.1"
}
}
}
22 changes: 14 additions & 8 deletions src/execute.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as vscode from 'vscode';

import * as path from 'path';
// import * as child_process from 'child_process';


const TERMINAL_NAME = "Batch Runner";
Expand All @@ -24,20 +25,25 @@ function getTerminal(bEnsureExists = true)
}
}

function runCommandBatchInTerminal(filepath: string) {
const terminal = getTerminal();
if (!terminal) {
return false;
}
terminal.sendText(`cmd /c "${filepath}"`, true);
terminal.show();

}

export function runBatFile(filepath: string) {
if (!isBatchFile(filepath)) {
const filename = path.basename(filepath);
vscode.window.showErrorMessage(`Batch Runner: ${filename} was not recognized as a batch file.`);
return false;
}
const terminal = getTerminal();
if (!terminal) {
return false;
}

terminal.sendText(filepath, true);
terminal.show();


// const a = child_process.exec(`cmd /c start ${filepath}`);
runCommandBatchInTerminal(filepath);

return true;
}

0 comments on commit 0a6b54a

Please sign in to comment.