Redirecting stderr

jPV · 134

jPV

  • Newbie
  • *
    • Posts: 2
    • Karma: +0/-0
on: April 11, 2021, 10:53:41 AM
Can you redirect stderr output from a shell program on AROS somehow? On other Amiga compatible platforms it's done by the * character, but I can't seem to get that work on AROS.

For example, the LhA command found in AROS distros seem to output its help text to stderr instead of stdout, so the usual lha >ram:output.txt doesn't work (results an empty file). The output can be captured on other Amiga systems by doing lha *>ram:output.txt, but that doesn't seem to do anything on AROS.. it doesn't even create empty files or anything.

So, is there some other way on AROS to capture these stderr outputs or is this a bug or non-implemented feature?



AMIGASYSTEM

  • Senior Member
  • ****
    • Posts: 450
    • Karma: +25/-1
Reply #1 on: April 11, 2021, 11:49:57 AM
Ciao jPV and welcome to the forum, i think the problem is the LHA Command and not AROS, did a Test with Unlzx or Unzip and it seems to work fine, see screenshot :)
« Last Edit: April 11, 2021, 11:56:44 AM by AMIGASYSTEM »



jPV

  • Newbie
  • *
    • Posts: 2
    • Karma: +0/-0
Reply #2 on: April 11, 2021, 02:00:28 PM
Thank you for the reply, but here's some more explanation about the issue.

There are two ways shell programs can output text into the console generally, and on Amiga too, see here: https://en.wikipedia.org/wiki/Standard_streams

UnLZX seems to output to the standard output (stdout), like most of the other programs too and that's not the problem, but LhA outputs to the standard error (stderr), which should be perfectly fine too and should be "capturable" somehow, but I can't capture it like usually on Amiga. So it's not LhA's fault, it's just outputting in a different way, but how to capture that on AROS?

On MorphOS it goes like this with the similar (unix port) of LhA:
Code: [Select]
Ram Disk:> c:lha >ram:output.txt
LHarc    for UNIX  V 1.02  Copyright(C) 1989  Y.Tagawa
LHx      for MSDOS V C2.01 Copyright(C) 1990  H.Yoshizaki
LHx(arc) for OSK   V 2.01  Modified     1990  Momozou
LHa      for UNIX  V 1.00  Copyright(C) 1992  Masaru Oki
LHa      for UNIX  V 1.14  Modified     1995  Nobutaka Watazaki
LHa      for UNIX  V 1.14d Modified     1997  Tsugio Okamoto
usage: lha [-]{axelvudmcp[q{num}][vnfodizg012]}[w=<dir>] archive_file [file...]
commands:                           options:
 a   Add(or replace) to archive      q{num} quiet (num:quiet mode)
 x,e EXtract from archive            v  verbose
 l,v List / Verbose List             n  not execute
 u   Update newer files to archive   f  force (over write at extract)
 d   Delete from archive             t  FILES are TEXT file
 m   Move to archive (means 'ad')    o  use LHarc compatible method (a/u)
 c   re-Construct new archive        w=<dir> specify extract directory (a/u/m/x/e)
 p   Print to STDOUT from archive    d  delete FILES after (a/u/c)
 t   Test file CRC in archive        i  ignore directory path (x/e)
                                     z  files not compress (a/u)
                                     g  [Generic] format (for compatibility)
                                     0/1/2 header level (a/u)
                                     e  TEXT code convert from/to EUC
Ram Disk:> list ram:output.txt lformat="Name:%N Size:%L"
Name:output.txt Size:empty
Ram Disk:> c:lha *>ram:output.txt
Ram Disk:> list ram:output.txt lformat="Name:%N Size:%L"
Name:output.txt Size:1337
Ram Disk:>

So the output to the standard error output is captured with the *>

You can even capture both outputs into single file by this:
c:lha >ram:output.txt *>>ram:output.txt
Then you don't need to know which output the program uses, and I would be using this method in my GUI programs that use shell commands for some operations to capture output for detecting errors and results.