0

I have written following code which uses nodejs callback. It correctly prints error when there is no telnet connection.

However, it is not printing Success! when telnet is performed successfully

When I manually perform telnet linux003 4102 I see a blank screen. Blank screen means telnet is connected successfully

var abc = require("expect-telnet");
abc("linux003:4102", 
function(err) {
  if (err) { 
    console.error(err);
  }
  else {
    console.log('Success!');
  }
});
meallhour
  • 13,921
  • 21
  • 60
  • 117

3 Answers3

0

according to expect-telnet doc, call back is only called when an error happens.

Kalpesh Kashyap
  • 824
  • 11
  • 18
  • How to print `Success!`? what changes do I need to make in my code to perform that – meallhour Oct 03 '19 at 04:31
  • @meallhour try "telnet-client" it returns promise also you can use async awit it will throw an error or sucess https://www.npmjs.com/package/telnet-client – Kalpesh Kashyap Oct 03 '19 at 04:35
  • I am trying to use `telnet-client`. can you help resolve the error faced there? https://stackoverflow.com/questions/58212553/socket-not-writable-while-using-telnet-client – meallhour Oct 03 '19 at 04:59
0

As per expect-telnet, the callback is called only when there will be an error. So, in following

var abc = require("expect-telnet");
abc("linux003:4102", 
function(err) {
  if (err) { 
    console.error(err);
  }
  else {
    console.log('Success!');
  }
});

the callback will only be called if there is an error. So Success! will not be printed.

Amit Singh
  • 426
  • 1
  • 4
  • 11
0

It looks like you might be able to leverage the out property in the expect step object:

out function: Output function, receives the output since the previous step.

const et = require("expect-telnet");

et("linux003:4102", [
  {
    expect: "some expected text", 
    out(output) {
      console.log("Success");
    }, 
    send: "exit\r"
}
], (err) => {
  if (err) console.error(err);
});

That being said, this package is no longer being maintained (see here), and the author recommends another package that looks like it would allow you to do this here).

Kai
  • 2,699
  • 1
  • 12
  • 7
  • It is still not displaying the `Success` message. I am trying to use `telnet-client`. can you help resolve the error faced there? https://stackoverflow.com/questions/58212553/socket-not-writable-while-using-telnet-client – meallhour Oct 03 '19 at 04:58