Run any Linux terminal command from TypeScript?

柔情痞子 提交于 2019-12-22 00:07:03

问题


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.


回答1:


In node.js you could spawn a child-process

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

exec('sudo apt-get update', (err, stdout, stderr) => {
  // your callback
});


来源:https://stackoverflow.com/questions/49700941/run-any-linux-terminal-command-from-typescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!