2013-04-22 5 views
0

나는 스폰에서 cmd를 실행하고 싶지만 명령을 실행할 때 응답을받지 못합니다. 어떻게 해결할 수 있습니까?nodejs에서 스폰에서 cmd를 실행하는 방법

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); 
}); 

답변

1

당신은 명령 dir에 대한 대가를 제공하지 않습니다. 창문에서는 \ r \ n입니다.

terminal.stdin.write(new Buffer('dir\r\n')); 

이렇게하면됩니다.

관련 문제