vendredi 27 mars 2015

JSCH to write to named pipe



I'm trying to write to write to a named pipe over a connection facilitated by jsch.



// connect to server
JSch ssh = new JSch();
JSch jsch = new JSch();
Session session = jsch.getSession(user, host, port);
session.setPassword(password);
session.setConfig("StrictHostKeyChecking", "no");
System.out.println("Establishing Connection...");
session.connect();
System.out.println("Connection established.");
System.out.println("Crating SFTP Channel.");
ChannelSftp sftpChannel = (ChannelSftp) session.openChannel("sftp");
sftpChannel.connect();
System.out.println("SFTP Channel created.");

// write to pipe
OutputStream strm = sftpChannel.put(remoteFile);

// failed attempts
// BufferedWriter wrtr = new BufferedWriter(new PrintWriter(new OutputStreamWriter(strm)));
// PrintWriter wrtr = new PrintWriter(new BufferedOutputStream(strm));

// Current version
BufferedWriter wrtr = new BufferedWriter(new PrintWriter(strm));

wrtr.write("hello world");
wrtr.flush();

session.disconnect();
sftpChannel.disconnect();
wrtr.close();


The connect to server part is essentially an exact copy from: SSH connection with Java


The code will even wait for something to be reading the pipe on the other side, meaning that if I don't use:



cat pipe


It will wait till I do so, and then once I have it will print out nothing and the cat pipe call will be over. Essentially it appears that I'm writing "" to the pipe instead of "hello world"


Any help would be much appreciated, thanks.




Aucun commentaire:

Enregistrer un commentaire