libssh을 사용하여 원격 서버에서 명령을 실행하고 있습니다. 여기 내 코드 (리턴 코드가 단순화 여기를 확인하지 않습니다,하지만 그들 모두 OK입니다) :pty 모드에서 libssh를 사용하는 stderr
stdout: foo
stderr: command not found: whoam
을 지금은 호출을 추가하는 경우 :
#include <stdio.h>
#include <stdlib.h>
#include <libssh/libssh.h>
int main() {
/* opening session and channel */
ssh_session session = ssh_new();
ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
ssh_options_set(session, SSH_OPTIONS_PORT_STR, "22");
ssh_options_set(session, SSH_OPTIONS_USER, "julien");
ssh_connect(session);
ssh_userauth_autopubkey(session, NULL);
ssh_channel channel = ssh_channel_new(session);
ssh_channel_open_session(channel);
/* command execution */
ssh_channel_request_exec(channel, "echo 'foo' && whoam");
char *buffer_stdin = calloc(1024, sizeof(char));
ssh_channel_read(channel, buffer_stdin, 1024, 0);
printf("stdout: %s\n", buffer_stdin);
free(buffer_stdin);
char *buffer_stderr = calloc(1024, sizeof(char));
ssh_channel_read(channel, buffer_stderr, 1024, 1);
printf("stderr: %s", buffer_stderr);
free(buffer_stderr);
ssh_channel_free(channel);
ssh_free(session);
return EXIT_SUCCESS;
}
출력은 axpected과 같다 ssh_channel_request_pty
단지 ssh_channel_open_session
후 :
...
ssh_channel channel = ssh_channel_new(session);
ssh_channel_open_session(channel);
ssh_channel_request_pty(channel);
ssh_channel_request_exec(channel, "echo 'foo' && whoam");
...
더 이상 어떤 표준 에러 출력이 없습니다
stdout: foo
stderr:
내가하여 명령을 변경하는 경우 :
ssh_channel_request_exec(channel, "whoam");
이제 오류 출력은 표준 출력에 읽기!
stdout: command not found: whoam
stderr:
ssh_channel_request_pty
이 누락 되었습니까?
를 실행하는 청각 장애를 가지고 있어야합니다sudo는 :
내용, 내가 때문에
sudo
으로 명령을 실행할 때 나는 다음과 같은 오류가 일부 서버에 그것을 사용하고 미안 해요, 당신은 sudo를에게
설명해 주셔서 감사합니다. 불행히도 루트 권한으로 ssh를 사용하거나 해당 서버의 sudoers 구성을 수정하는 것은 허용되지 않습니다. 다음 해결 방법을 찾아야 할 것 같습니다! – julienc