G'day Nobby,

I see that the STDOUT/STDERR problem has been explained. Here's some additional comments.

Here's some output from my command line:

$ ls -al a_real_dir total 4 drwxr-xr-x 1 ken None 0 Nov 19 18:20 . drwxr-xr-x 1 ken None 0 Nov 19 19:10 .. -rw-r--r-- 1 ken None 0 Nov 19 18:20 demo_file_A -rw-r--r-- 1 ken None 0 Nov 19 18:20 demo_file_B $ ls -al not_a_real_dir ls: cannot access 'not_a_real_dir': No such file or directory

Here's a demo script that uses all of the points I raised:

#!/usr/bin/env perl use strict; use warnings; use autodie; use HTML::Escape 'escape_html'; my %commands = (ls => '/usr/bin/ls -al'); my @targets = qw{a_real_dir not_a_real_dir}; my $program = 'ls'; print "<html>\n<head>...</head>\n<body>\n"; for my $target (@targets) { my $cmd = "$commands{$program} $target 2>&1"; print '<h1>', escape_html($cmd), "</h1>\n<pre>\n"; { open my $cmd_pipe, '-|', $cmd; print escape_html($_) while <$cmd_pipe>; } print "</pre>\n"; } print "</body>\n</html>\n";

Output:

<html> <head>...</head> <body> <h1>/usr/bin/ls -al a_real_dir 2&gt;&amp;1</h1> <pre> total 4 drwxr-xr-x 1 ken None 0 Nov 19 18:20 . drwxr-xr-x 1 ken None 0 Nov 19 19:10 .. -rw-r--r-- 1 ken None 0 Nov 19 18:20 demo_file_A -rw-r--r-- 1 ken None 0 Nov 19 18:20 demo_file_B </pre> <h1>/usr/bin/ls -al not_a_real_dir 2&gt;&amp;1</h1> <pre> /usr/bin/ls: cannot access &#39;not_a_real_dir&#39;: No such file or d +irectory </pre> </body> </html>
"I have omitted a lot of the header and html code, ..."

That's fine. My code is only intended as a demo example: adapt to your needs.

— Ken


In reply to Re: null output on program by kcott
in thread null output on program by Nobby

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.