节点。如何编写到java-childprocess-stdin

时间:2021-01-31 21:57:38

I've written a node.js-server who could spawn a java childprocess from a webinterface and display the stdout of the jar to the interface. now I need to send some commands over the stdin to the jar and thath's my problem:

我写的一个节点。可以从webinterface生成java子进程并将jar的stdout显示到接口的js-server。现在我需要通过stdin向jar发送一些命令,这是我的问题:

I'm spawning the server:

我在产卵服务器:

jar = cp.spawn('java', ['-Xmx1024M', '-jar', dir+'craftbukkit.jar', '-o true','-nojline'], {
cwd:dir);

Trying to send some command:

试着发出一些命令:

jar.stdin('stop\n');

But It doesen't do anything. In Other Childprocesses it worked like this but now i've got no idea how to do this. Anybody an Idea?

但它什么都不做。在其他的儿童过程中它是这样工作的但是现在我不知道怎么做。有人知道吗?

Thx Guys!

Thx的家伙!

1 个解决方案

#1


4  

Your jarobject is a ChildProcess object, which has three streams: stdin, stdout, stderr. They are not functions, but streams that you can read from (stdout and stderr) and write to (stdin).

jarobject是一个ChildProcess对象,它有三个流:stdin、stdout和stderr。它们不是函数,而是可以从(stdout和stderr)读取并写入(stdin)的流。

Here is an example:

这是一个例子:

jar.stdin.write('stop\n');
jar.stdout.pipe(process.stdout);

which will write some data to the standard input of your child process, and pipe its output to the standard output of your Node process (ie. the console).

它将把一些数据写入子进程的标准输入,并将其输出传输到节点进程的标准输出(即。控制台)。

Note that the write() call is asynchronous: there may be a small delay between the time you called write() and the time it is really written to the process input.

注意,write()调用是异步的:从调用write()的时间到真正写入流程输入的时间之间可能有一个小的延迟。

For an overview of streams, you can read The Stream Handbook.

对于流的概述,您可以阅读流手册。

#1


4  

Your jarobject is a ChildProcess object, which has three streams: stdin, stdout, stderr. They are not functions, but streams that you can read from (stdout and stderr) and write to (stdin).

jarobject是一个ChildProcess对象,它有三个流:stdin、stdout和stderr。它们不是函数,而是可以从(stdout和stderr)读取并写入(stdin)的流。

Here is an example:

这是一个例子:

jar.stdin.write('stop\n');
jar.stdout.pipe(process.stdout);

which will write some data to the standard input of your child process, and pipe its output to the standard output of your Node process (ie. the console).

它将把一些数据写入子进程的标准输入,并将其输出传输到节点进程的标准输出(即。控制台)。

Note that the write() call is asynchronous: there may be a small delay between the time you called write() and the time it is really written to the process input.

注意,write()调用是异步的:从调用write()的时间到真正写入流程输入的时间之间可能有一个小的延迟。

For an overview of streams, you can read The Stream Handbook.

对于流的概述,您可以阅读流手册。