Reputation: 565
I'm using npm node-cmd in my react app and it is failing on cmd.get (sending commands to the terminal).
All my code works in vanilla html and javascript but I need it to work in React. I'm thinking my setup is wrong in 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);
}
I'm getting TypeError: exec is not a function
Upvotes: 1
Views: 6182
Reputation: 2562
exec is not a function
tell me that things get wrong on node-cmd
.
Just open the lib:
var exec = require('child_process').exec;
That line will never work from browser. Just try with a single ls
Upvotes: 1