节点 ssh-exec 将一些数据通过管道传输到远程进程
node ssh-exec pipe some data to the remote process
抱歉,可能做错了什么,但在输出文件中找不到任何内容,请参见下文:
var exec = require('ssh-exec');
var fs = require('fs');
file = fs.createWriteStream('rep-output.txt');
process.stdin
.pipe(exec(command, host))
.pipe(file);
file.end();
这里是:
[node]$ cat rep-output.txt
[node]$
但是因为 'command' 是 'touch output.txt' 我可以看到它在远程 'host':
上正确执行
[remote]$ ls -l output.txt
[remote]$-rw-rw-r-- 1 irekr irekr 0 Jul 4 10:53 output.txt
如果 'command' 即 'ls -l' 仍然 'rep-output.txt' 为空
我认为这是因为您在开始写入之前关闭了流。删除 file.end()
file = fs.createWriteStream('rep-output.txt');
process.stdin
.pipe(exec(command, host))
.pipe(file);
当您 pipe
流式传输时,它将负责在输入流结束时结束写入流。见 doc:
By default end() is called on the destination when the source stream
emits end, so that destination is no longer writable. Pass { end:
false } as options to keep the destination stream open.
抱歉,可能做错了什么,但在输出文件中找不到任何内容,请参见下文:
var exec = require('ssh-exec');
var fs = require('fs');
file = fs.createWriteStream('rep-output.txt');
process.stdin
.pipe(exec(command, host))
.pipe(file);
file.end();
这里是:
[node]$ cat rep-output.txt
[node]$
但是因为 'command' 是 'touch output.txt' 我可以看到它在远程 'host':
上正确执行[remote]$ ls -l output.txt
[remote]$-rw-rw-r-- 1 irekr irekr 0 Jul 4 10:53 output.txt
如果 'command' 即 'ls -l' 仍然 'rep-output.txt' 为空
我认为这是因为您在开始写入之前关闭了流。删除 file.end()
file = fs.createWriteStream('rep-output.txt');
process.stdin
.pipe(exec(command, host))
.pipe(file);
当您 pipe
流式传输时,它将负责在输入流结束时结束写入流。见 doc:
By default end() is called on the destination when the source stream emits end, so that destination is no longer writable. Pass { end: false } as options to keep the destination stream open.