Linux仮想マシン(JSch
)に接続するアプリケーションを作成しようとしていて、LinuxにOS名やカーネルバージョンなどのいくつかの質問をします。私はそれに成功し、アプリケーションは動作しますが、Eclipseコンソールでのみ動作します。JavaFXラベルがテキストを正しく更新しない
ラベルやTextAreaで印刷しようとすると、変なことが起こっています。たとえば、ラベルに印刷しようとすると、最後のコマンドだけが出力されます。私はTextAreaのでそれをしようとすると、それはすべてを出力しますが、1行では、と私はどのようにブレーキラインをするのか分からない...ここで
はコードです:どのようにここで
import javafx.fxml.FXML;
import javafx.scene.canvas.Canvas;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
public class MainWindowController {
@FXML private TextField ip_text_field, username_text_field, password_text_field;
@FXML private Label output;
String ip, username, pass;
private Main main;
public void setMain(Main main){
this.main = main;
}
public String getIP(){ip = ip_text_field.getText(); return ip;}
public String getUsername(){username = username_text_field.getText(); return username;}
public String getPassword(){pass = password_text_field.getText(); return pass;}
public void connectButtonFunction(){
try{
String command = "lsb_release -a | grep -i Description && uname -mrs";
String host = getIP();
String user = getUsername();
String password = getPassword();
JSch jsch = new JSch();
Session session = jsch.getSession(user, host, 22);
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);;
session.setPassword(password);
session.connect();
Channel channel = session.openChannel("exec");
((ChannelExec)channel).setCommand(command);
channel.setInputStream(null);
((ChannelExec)channel).setErrStream(System.err);
InputStream input = channel.getInputStream();
channel.connect();
//System.out.println("Channel Connected to machine " + host + " server with command: " + command);
try{
InputStreamReader inputReader = new InputStreamReader(input);
BufferedReader bufferedReader = new BufferedReader(inputReader);
String line = null;
while((line = bufferedReader.readLine()) != null){
//System.out.println(line);
output.setText(line);
}
bufferedReader.close();
inputReader.close();
}catch(IOException ex){
ex.printStackTrace();
}
channel.disconnect();
session.disconnect();
}catch(Exception ex){
ex.printStackTrace();
}
}
}
ですラベルのように見えます。