简体   繁体   English

从 Angular 4 组件运行 Linux 命令

[英]Run Linux command from Angular 4 component

Requirement is to fetch the output of a shell script's after running it from the Angular 4 component at the beginning during compilation ie just before the website is launched.要求是在编译开始时(即在网站启动之前)从 Angular 4 组件运行 shell 脚本后获取其输出。 I have already gone through the threads in stackoverflow ie 49700941 and 41637166 .我已经完成了 stackoverflow 中的线程,即4970094141637166

From the first thread i tried to use the below code, but getting error:从第一个线程开始,我尝试使用以下代码,但出现错误:

Module not found: Error: Can't resolve 'child_process' in 'app/component ...'未找到模块:错误:无法解析“应用程序/组件...”中的“子进程”

const exec = require('child_process').exec;   // Can't resolve 'child_process' error coming from this line

exec('/home/myDir/init_setup.sh', (err, stdout, stderr) => {
    if (err){
       console.error(err);
       return;
    };
    console.log(stdout);
    console.log(stderr);
    /** 
     remaining logics
    */
});

Please let me know if I need to import some library explicitly or not to avoid this error.请让我知道是否需要显式导入某些库以避免此错误。

The modern browsers opens the webpage in isolated sandbox so they have have no access to clients' computers.现代浏览器在隔离的沙箱中打开网页,因此他们无法访问客户的计算机。
Imagine the damage that could be done if a black hat could run batch script on computer that opens his webpage.想象一下,如果黑帽可以在打开其网页的计算机上运行批处理脚本,可能造成的损害。
The only way to run the script is to run the desktop application on client's machine.运行脚本的唯一方法是在客户端机器上运行桌面应用程序。

The example code you provided is Node.js code, the desktop framework that user have to install on his machine and run the code intentionally.您提供的示例代码是 Node.js 代码,用户必须在他的机器上安装并有意运行代码的桌面框架。 There's ( fortunately! ) no way to run it remotely via webpage. 幸运的是! )无法通过网页远程运行它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM