Is it possible to redirect STDERR to the same file as STDOUT.
The equivalent command in linux:
./myProgram 1>log 2>&1
I have looked at the Amiga wiki, but it does not seem to mention it. It seems that that STDOUT can be redirected to a file, of course, but STDERR cannot be redirected to the same file.
#include <stdio.h>
int main()
{
fprintf(stdout,"STDOUT\n");
fprintf(stderr,"STDERR\n");
return 0;
}
@rjd324 Redirecting stdin and stdout to the same file is possible and often used ("run <>NIL: foobar"), should be possible with stdout and sdterr as well, and with all 3. Try something like "foobar *>>out", but that might only redirect stderr but in appending mode like "foobar >>out" does for stdout, or "foobar >*>out".
I still cannot figure out what syntax to actually use to do this. You are right, STDOUT,STDIN seems to work okay with that syntax and this is often done, but redirecting STDOUT and STDERR to the same file seems impossible through the shell.
But, this test program demonstrates that it is somehow possible:
Ny Shell-proces, nr. 22
22.WB-F: 0 0 [0,000.396] Mandag 12/06-2023 00:36:10
$ delete RAM:p
22.WB-F: 0 0 [0,000.585] Mandag 12/06-2023 00:36:20
$ dir xx >> RAM:p *>> RAM:p
22.WB-F: 20 205 [0,000.646] Mandag 12/06-2023 00:36:30
$ type RAM:p
DIR: Kunne ikke finde oplysninger om "xx".
DIR: objektet findes ikke
22.WB-F: 0 0 [0,001.372] Mandag 12/06-2023 00:36:36
$
Quote:
Why append? This is not what I would have expected.
Perhaps because if you don't append, but just write, the first redirection (the STDOUT) locks the file so the second one (STDERR) can't write to it. And maybe they both try to verify that they can get their locks before either one starts to actually open (create) the file, because it seems to fail without even creating the file.
And that probably also means it wouldn't help using append only for one of them.
is that you now have two streams writing to the same file. Neither stream knows what the other has written, so parts of the output will be overwritten.
Hi, yes I am aware that printing to separate files works but thank you for the suggestion; the issue being that interleaving of output is trashed in the sense that if you append the file containing only the STDERR to the file containing on the STDOUT (vice versa) then you no longer get the true time of which the information was output.
I am extending that test program written above and will need to test out some more complex use-cases. That program seems to be handling the situation but I have not tried more extensive testing.
If it does, then I guess I will can upload that program and I will probably name it "&>". As in:
&> <OUT_FILE> <COMMAND>
Where <COMMAND> can take any number of white spaced tokens etc.
If liberty means anything at all, it means the right to tell people what they do not want to hear. George Orwell.
In the absense of a proper solution to redirection STderr to Stdout, what you really need is a custom PIPE: that has two inputs amd one output that can mux the output into a single stream.