javascript - 在 React 中使用 node-cmd... 获取 TypeError: exec is not a function
问题描述
我在我的反应应用程序中使用 npm node-cmd 并且在 cmd.get 上失败(向终端发送命令)。
我所有的代码都在 vanilla html 和 javascript 中工作,但我需要它在 React 中工作。我认为我的设置反应错误。
import cmd from 'node-cmd';
let projDir = result.substr(0, result.lastIndexOf('/')+1);
let projFile = result.substr(result.lastIndexOf('/')+1);
let copyFile = "cp '" + projFile + "' pproXML.gz";
let unzip = "gunzip -d pproXML.gz";
let rename = "mv pproXML pproXML.prproj";
let targetXml = projDir + 'pproXML.prproj';
let cmdStr =
"cd ..'" + projDir + "'\n" +
copyFile + "\n" +
unzip + "\n" +
rename + "\n" +
"ls";
// FAILS HERE
cmd.get(
cmdStr,
function(err, data, stderr){
alert(data);
}
我收到 TypeError: exec is not a function
解决方案
exec is not a function
告诉我事情出错了node-cmd
。
只需打开库:
var exec = require('child_process').exec;
该行将永远无法在浏览器中使用。试一试ls
推荐阅读
- java - 我收到错误。(空对象引用上的'android.app.ActivityThread.getApplicationThread()')
- php - Get only those array values which are repeating N number of times in PHP
- php - Prevent Submit Button Jquery On unique username
- swift - 我想在单个文本字段中检查手机号码和电子邮件 ID 的验证。我应该如何验证这一点?
- javascript - how to set a condition in an array using jquery?
- swift - How to fix "Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value" while using tableview.reloaddata
- reactjs - 反应 BootstrapTable 的分页改变 sizePerPage 的问题
- hyperledger-fabric - 处理超级账本结构中的多重背书
- android - 颤振升级后扩展内的文本不换行
- mongodb - mongodb查找中的条件“来自”