Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run any Linux terminal command from TypeScript?

Is there a way to execute a Linux terminal command directly from within a TypeScript class? The idea is to do something similar to:

let myTerminal = new LinuxTerminal();
let terminalResult = myTerminal.run("sudo apt-get update");

EDIT:

I run this through Node JS with Angular.

like image 462
Socrates Avatar asked May 12 '26 19:05

Socrates


1 Answers

In node.js you could spawn a child-process

const { exec } = require('child_process');

exec('sudo apt-get update', (err, stdout, stderr) => {
  // your callback
});
like image 122
Kristianmitk Avatar answered May 15 '26 08:05

Kristianmitk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!