s****n 发帖数: 700 | 1 the external program is excuted via ssh. Thank you very much | c**t 发帖数: 2744 | 2 you can catch stdout and stderr
【在 s****n 的大作中提到】 : the external program is excuted via ssh. Thank you very much
| s****n 发帖数: 700 | 3 sorry I am not quite understand.
Say I want to write a program in serv1, the program does 'ssh serv2; ls'.
How can I get the result of 'serv2 ls' at serv1's program.
【在 c**t 的大作中提到】 : you can catch stdout and stderr
| X****r 发帖数: 3557 | 4 #include
#include
int main() {
int fd[2];
pipe(fd);
if (fork()) {
close(1);
dup2(fd[1], 1);
execlp("ssh", "ssh", "serv2", "ls");
} else {
int len;
char buf[256];
while ((len = read(fd[0], buf, 256)) >= 0) {
/* Process piece of output from buf[0] to buf[len-1]. */
}
wait(0);
}
}
ls'.
【在 s****n 的大作中提到】 : sorry I am not quite understand. : Say I want to write a program in serv1, the program does 'ssh serv2; ls'. : How can I get the result of 'serv2 ls' at serv1's program.
|
|