I am trying to run a python file called testingFile.py inside a VS Code extension as shown below:
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
const { ChildProcess } = require('child_process');
const vscode = require('vscode');
const { exec } = require('node:child_process');
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
let disposable = vscode.commands.registerCommand('fileDialog.openFile', function () {
const options = {
canSelectMany: false,
openLabel: 'Open'
};
vscode.window.showOpenDialog(options).then(fileUri => {
if (fileUri && fileUri[0]) {
console.log('Selected file: ' + fileUri[0].fsPath);
}
});
});
context.subscriptions.push(disposable);
}
// this method is called when your extension is deactivated
function deactivate() {}
module.exports = {
activate,
deactivate
}
all this extension does is open a file dialog. when I would like to do is as follows: once I get the file path from the user, I want to trigger the execution of testingFile.py. please note that testingFile.py is located in the same location as extension.ts (the code seen above). I was initially trying to use spawn or exec. I am having a hard time getting them to work.
Perhaps it could also be run using vs code's built in commands such as
vscode.commands.executeCommand('python.execInInterminal...)
but I cant quite figure out how it works.
Any advice would be greatly appreciated!