in reply to null output on program
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>&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>&1</h1> <pre> /usr/bin/ls: cannot access 'not_a_real_dir': 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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: null output on program
by Nobby (Novice) on Nov 20, 2022 at 05:45 UTC |