我有一個libssh(libssh.org)的問題。我需要在遠程服務器上運行makefile。我用命令 「channel_request_exec」 做到這一點:如何用libssh運行makefile?
int SSHExecCmd (void(* MessSender)(char* CurMessage, bool IsError, CWnd* MainWnd),ssh_session session, CString & ShellEcho, char * cmd, CWnd* MainWnd)
{
ssh_channel channel;
int rc;
channel = ssh_channel_new(session);
if (channel == NULL) return SSH_ERROR;
rc = ssh_channel_open_session(channel);
if (rc != SSH_OK)
{
ssh_channel_free(channel);
return rc;
}
rc = ssh_channel_request_exec(channel, cmd);
if (rc != SSH_OK)
{
ssh_channel_close(channel);
ssh_channel_free(channel);
return rc;
}
char buffer[256];
unsigned int nbytes;
nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
while (nbytes > 0)
{
if (fwrite(buffer, 1, nbytes, stdout) != nbytes)
{
ssh_channel_close(channel);
ssh_channel_free(channel);
return SSH_ERROR;
}
nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
}
if (nbytes < 0)
{
ssh_channel_close(channel);
ssh_channel_free(channel);
return SSH_ERROR;
}
return SSH_OK;
}
Makefile文件位於根:
all: mpi_cuda.o pattern2d.o
mpicc mpi_cuda.o pattern2d.o -o mpi_cuda -lrt -lpthread -L/opt/cuda/lib64 -lcudart -lm
mpi_cuda.o: mpi_cuda.c
mpicc -g -std=c99 -D_GNU_SOURCE -I/opt/cuda/include -c $< -o [email protected]
pattern2d.o: pattern2d.cu
nvcc -g -c $< -o [email protected]
我發送一個命令 「製造」 和回波接收:
mpicc -g -std=c99 -D_GNU_SOURCE -I/opt/cuda/include -c mpi_cuda.c -o mpi_cuda.oda
,但沒有發生(編譯不執行)。
如果我用油灰使:一切工作。 Echo:
make
mpicc -g -std=c99 -D_GNU_SOURCE -I/opt/cuda/include -c mpi_cuda.c -o mpi_cuda.o
mpi_cuda.c: В функции ‘main’:
mpi_cuda.c:148: предупреждение: недостаточно аргументов для указанного формата
nvcc -g -c pattern2d.cu -o pattern2d.o
mpicc mpi_cuda.o pattern2d.o -o mpi_cuda -lrt -lpthread -L/opt/cuda/lib64 -lcudart -lm
我該如何解決這個問題?
我在兩臺服務器上測試選項與日誌記錄(bash的-c 「做法> make_out.txt 2> make_err.txt」)。 首先make_err.txt: 化妝:找不到命令 化妝:mpicc *** [全部]錯誤127 二: 化妝:NVCC:命令未找到 化妝:*** [pattern2d.o ]錯誤127 通過試驗和錯誤我收到的錯誤代碼只能在一臺服務器上工作。使用異步讀取(ssh_channel_read_nonblocking)。 但是爲什麼在這種情況下可以使用mpicc?這很奇怪...... – snk
@snk更新了將環境轉儲到env.txt的答案,以及有關比較工作和非工作輸出(尤其是env.txt)的註釋。 – hyde
抱歉,延遲。當你連接libssh時,env.txt由12個變量組成。用膩子34.這裏的問題,但爲什麼不明確。 – snk