I am trying to test a specific server is up and running on a certain port so I am using
$result = `echo exit | telnet 127.0.0.1 9443`; print $result;
Here I am using localhost for privacy issues The expected behavior is that it should print "...Could not open connection to the host, on port 9443: Connect failed", this way I know that the server is not running. but it prints an empty string
Any help on this
The failure message is printed to
STDERR
, while backticks return only what goes toSTDOUT
.You can redirect the
STDERR
stream to theSTDOUT
streamSee I/O redirection.
There are more rounded ways to do this, using various forms of
open
. See it in perlfaq8. There are also various modules for this. The Capture::Tiny makes it rather easy.This prints for me
The module has many more capabilities. From the docs