简体   繁体   English

如何在MEAN堆栈中执行Shell命令行?

[英]How can I execute shell command line in MEAN stack?

Hello I'm a very newbie in MEAN stack. 您好,我是MEAN堆栈中的新手。

Previously I used php for web development, and I usually used "shell_exec" to browse server json files and read them. 以前,我使用php进行Web开发,并且通常使用“ shell_exec”浏览服务器json文件并读取它们。

How can I execute shell command line in MEAN stack? 如何在MEAN堆栈中执行Shell命令行?

What is "shell_exec" in MEAN stack? 什么是MEAN堆栈中的“ shell_exec”?

Thanks in advance :) 提前致谢 :)

If you need to browse json - it's much simplier: 如果您需要浏览json-简单得多:

const data = require('./some-file.json');

In case if you still need exec, here it is: 如果您仍然需要执行程序,这里是:

const { exec } = require('child_process');
exec('cat *.js bad_file | wc -l', (error, stdout, stderr) => {
  if (error) {
    console.error(`exec error: ${error}`);
    return;
  }
  console.log(`stdout: ${stdout}`);
  console.log(`stderr: ${stderr}`);
});

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

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