2016-10-25 2 views
0

저는 Linux에서 openssl을 호출하는 node.js 프로그램을 작성하고 있습니다. 내가 자동으로 답변을 작성하고 각각에 대한 'Enter'키를 누르 내 Node.js를 프로그램을 원하는CLI를 호출하고 Node.js의 프롬프트에 응답하는 방법

Country Name (2 letter code) [AU]: 
State or Province Name (full name) [Some-State]: 
Locality Name (eg, city) []: 
Organization Name (eg, company) [Internet Widgits Pty Ltd]: 
Organizational Unit Name (eg, section) []: 
Common Name (e.g. server FQDN or YOUR name) []: 
Email Address []: 

Please enter the following 'extra' attributes 
to be sent with your certificate request 
A challenge password []: 
An optional company name []: 

:

var cmd = 'openssl req -new -sha256 -key delegation.key -out delegation.csr'; 

이 사용자 입력에 대한 일련의 프롬프트를 설정합니다.

tx!

답변

0

사용 child_process

var childprocess = require('child_process'); 
var openssl = childprocess.spawn('openssl', ['req','-new','-sha256','-key','delegation.key','-out','delegation.csr']); 
openssl.stdout.setEncoding('utf8'); 

var current = ''; 
openssl.stdout.on("data", function(data) { 
    current += data; 
    if (current[current.length-1] == '\n') { 

     // Handle text in "current" (this is what openssl has written) 

     // if we should reply { 

      var reply = 'MY REPLY TO WHAT IS IN CURRENT'; 

      childProcess.stdin.write(reply + '\n'); 

     // } else { 
      // (if we are finished - have no more replies) 
      // openssl.stdin.end(); 
     // } 
     current = ''; 
    } 
});