Net::SSH::Perl ...... how to print the output in a proper format

Hi Guys,

my $cmd = "ls -l"; #........ {or let it be as # my $cmd= "ls"; }
my $ssh = Net::SSH::Perl->new($host);
$ssh->login($user, $pass);
my($stdout, $stderr, $exit) = $ssh->cmd("$cmd");
print $stdout;

the script works fine, but i am unable to see the output getting displayed in a correct format.
i.e output of the above script is as follows:

total 79936 -rw-r--r-- 1 readonly bin 306 Feb 13 2008 a1.sh -rw-r--r-- 1 readonly bin 216 Oct 11 2007 accesslog1.sh -rw-r--r-- 1 readonly bin 216 Oct 11 2007 accesslog2.sh -rw-r--r-- 1 readonly bin 1248 Feb 13 2008 ca.log -rw-r--r-- 1 readonly bin 38143 Jul 17 2008 17072008_Run2 drwxr-xr-x 2 readonly bin 4096 Apr 9 2008 s -rw-r--r-- 1 readonly bin 14739 Jul 17 2008 07172008_Run2 -rw-r--r-- 1 readonly bin 15152 Jul 16 2008 17_07_2008

Instead of displaying the output as,

total 79936
-rw-r--r-- 1 readonly bin 306 Feb 13 2008 a1.sh
-rw-r--r-- 1 readonly bin 216 Oct 11 2007 accesslog1.sh
-rw-r--r-- 1 readonly bin 216 Oct 11 2007 accesslog2.sh
-rw-r--r-- 1 readonly bin 1248 Feb 13 2008 ca.log
drwxr-xr-x 2 readonly bin 4096 Apr 9 2008 s
-rw-r--r-- 1 readonly bin 14739 Jul 17 2008 Analysis_07172008_Run2
-rw-r--r-- 1 readonly bin 15152 Jul 16 2008 17_07_2008

Please anyone let me know your valuable suggestions to display the o/p as
total 79936
-rw-r--r-- 1 readonly bin 306 Feb 13 2008 a1.sh
-rw-r--r-- 1 readonly bin 216 Oct 11 2007 accesslog1.sh
-rw-r--r-- 1 readonly bin 216 Oct 11 2007 accesslog2.sh
-rw-r--r-- 1 readonly bin 1248 Feb 13 2008 ca.log
drwxr-xr-x 2 readonly bin 4096 Apr 9 2008 s
-rw-r--r-- 1 readonly bin 14739 Jul 17 2008 Analysis_07172008_Run2
-rw-r--r-- 1 readonly bin 15152 Jul 16 2008 17_07_2008

Not only for 'ls' command, but executing any commands using Net::SSH::Perl connection displays the output as a single line.

Please let me know your valuable suggestions.

Thanks in Advance

In the future, please use [code ][/code ] tags, it improves readability.

What's the output if you change the last line to print ref($stdout)? Maybe it doesn't return a string but an array of strings.

As i tried replacing last line with print ref($stdout); displays a blank output (i.e no output)

Also if i replace last two lines of code as ,
my(@stdout, $stderr, $exit) = $ssh->cmd("$cmd");
print @stdout;

i see no difference between $stdout & @stdout outputs.

If ref() returns an empty string that means that it isn't a reference to anything. And assigning a scalar to an array just makes that scalar the first element of the array.

I guess that the newline gets lost somewhere during transfer (either dropped by the server or Net::SSH::Perl itself) since in the code they're only appending one line of returned data to the previous lines, returning all of it in $stdout/$stderr.

Yes, you are right which is expected.

But i am looking for some way/solution where we can print the output as if executing a command in a unix box displays the output in a clear format. At present i am using CGIPerl Script to display the output on a browser and i am able to print the output on a browser in this way ....

total 79936 -rw-r--r-- 1 readonly bin 306 Feb 13 2008 a1.sh -rw-r--r-- 1 readonly bin 216 Oct 11 2007 accesslog1.sh -rw-r--r-- 1 readonly bin 216 Oct 11 2007 accesslog2.sh -rw-r--r-- 1 readonly bin 1248 Feb 13 2008 ca.log -rw-r--r-- 1

Though at present i am having a solution where we can split the output of 'ls' command as the output will be of this format ...

-rw-rw-rw- 1 root dir 104 Dec 25 19:32 filename

we can split the above output as fields i.e at filename field and we can assign this to an array and there by we can print the output.
i.e
total 79936
-rw-r--r-- 1 readonly bin 306 Feb 13 2008 a1.sh
-rw-r--r-- 1 readonly bin 216 Oct 11 2007 accesslog1.sh
-rw-r--r-- 1 readonly bin 216 Oct 11 2007 accesslog2.sh
-rw-r--r-- 1 readonly bin 1248 Feb 13 2008 ca.log
drwxr-xr-x 2 readonly bin 4096 Apr 9 2008 s

But this is just a temporary solution which works fine for 'ls -l' command. But tomorrow if we wish to execute other commands such as "ls", "cat" and so on... it wont work.

But i appreciate 4ur thoughts & ur precious time.....
Still lets hope for a solution where we can print the output in a format wrapped at every newline of output and display the same on a browser.

Thanks in Advance,
GS

Question: does the newline always get dropped or only when displayed in the browser? Is it present in the HTML source?
The reason I'm asking is because you never mentioned a browser before.