我有一个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