Reputation: 121
I want to run cmd in the spawn, but when I run the command, you will not get a reply. How do I fix this?
var terminal = require('child_process').spawn('cmd', ['/K'], { timeout : 1000*60*60*24 });
terminal.stdin.setEncoding = 'utf-8';
terminal.stdin.write(new Buffer('dir'));
terminal.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
terminal.on('exit', function (code) {
// console.log('child process exited with code ' + code);
});
Upvotes: 0
Views: 2809
Reputation: 48003
You are not giving return for command dir
. In windows it is \r\n.
terminal.stdin.write(new Buffer('dir\r\n'));
This will work.
Upvotes: 2