0
이 작동하지 않습니다.Node.js child.stdin.write가 자식 프로세스를 실행하려고 할 때 어떤 텍스트를 stdin 할 때 오류가 발생하면
var spawn = require('child_process').spawn;
var child = spawn('java', ['HelloWorld', 'HelloWorld.class']);
child.stdin.setEncoding('utf-8');
child.stdout.pipe(process.stdout);
child.stdin.write("tratata\n");
// child.stdin.end();
가 발생합니다 :이 프로세스를 실행 스크립트의
import java.io.Console;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("started");
Console console = System.console();
while (true) {
String s = console.readLine();
System.out.println("Your sentence:" + s);
}
}
}
코드 :
events.js:161
throw er; // Unhandled 'error' event
^
Error: read ECONNRESET
at exports._errnoException (util.js:1028:11)
at Pipe.onread (net.js:572:26)
통지를, child.stdin와 내가 주석 라인 여기 는 자식 프로세스의 코드 .종료(); 스크립트 작업을해야하는 반응
FWIW'child.stdin.setEncoding ('utf-8');'이 올바르지 않습니다. 'setEncoding()'은'Readable' 스트림을위한 것이지만'child.stdin'는'Writable' 스트림으로 사용됩니다. – mscdex
또한 행 끝 부분에 LF 대신 CRLF를 사용 했습니까 (예 :'child.stdin.write ("tratata \ r \ n");')? – mscdex