问题描述
- JSCH 连接linux可以执行c程序吗?
-
jsch怎么执行可执行文件(是一个c语言程序) 直接用文件名不行
解决方案
怎样在linux下编写C程序并编译执行
linux下的C语言计算程序执行时间
解决方案二:
这里执行的sh,你换成你c程序路径。
public void cmremove()
{
try
{
JSch jsch = new JSch();
Session session = jsch.getSession(user, host, port);
UserInfo ui = new SUserInfo(pass, null);
session.setUserInfo(ui);
session.setPassword(pass);
session.connect();
ChannelExec channelExec = (ChannelExec)session.openChannel("exec");
InputStream in = channelExec.getInputStream();
channelExec.setCommand("./repoUpdate.sh");
channelExec.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line;
int index = 0;
while ((line = reader.readLine()) != null)
{
System.out.println(++index + " : " + line);
}
int exitStatus = channelExec.getExitStatus();
channelExec.disconnect();
session.disconnect();
if(exitStatus < 0){
System.out.println("Done, but exit status not set!");
}
else if(exitStatus > 0){
System.out.println("Done, but with error!");
}
else{
System.out.println("Done!");
}
}
catch(Exception e)
{
System.err.println("Error: " + e);
}
}
时间: 2024-12-30 18:46:58