skip to Main Content

Trying to write an extension that executes the terminal command.

For example:
if I execute the sensors command in the terminal, it will show the CPU temperature. I want to create a command that prints this information into the terminal upon activation.

I have tried by placing it with registercommand like following.

let d = vscode.commands.registerCommand(sensors);
context.subscriptions.push(d);

Does anyone know where to put these type of terminal commands?

Environment:
Ubuntu 22.04.1 LTS

AMD Ryzen 3

2

Answers


  1. Chosen as BEST ANSWER

    Used child_process to execute the terminal command from extension (One click output)

    
    exec('sensors', (error, stdout, stderr) => {
        if(error){
            console.log(`error: ${error.message}`);
            return;
        }
        if(stderr){
            console.log(`stderr: ${stderr}`);
            return;
        }
        console.log(`stdout: ${stdout}`);
    });
    

  2. One possible approach is to use Node.js’ child_process module, run the sensor command in a separate process with this, read the output and print that in an output channel in VS Code.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search