Who's Online
17 user(s) are online (
12 user(s) are browsing
Forums )
Members: 2
Guests: 15
smarkusg ,
tekmage ,
more...
Headlines
libmodplug.lha - development/library/audio
May 13, 2025
libsdl2_mixer.lha - development/library/audio
May 13, 2025
libvorbis.lha - development/library/audio
May 13, 2025
libx264.lha - development/library/misc
May 13, 2025
retroarch_cores_installer.lha - emulation/gamesystem
May 13, 2025
igame.lha - utility/misc
May 13, 2025
libogg.lha - development/library/audio
May 12, 2025
libtheora.lha - development/library/graphics
May 12, 2025
faac.lha - audio/convert
May 10, 2025
faad2.lha - audio/convert
May 10, 2025
Topic options
View mode
Newest First
Redirect STDERR and STDOUT to the same file
Posted on:
2023/4/9 15:49
#1
Quite a regular
Joined: 2021/12/20 2:52Last Login
: Yesterday 23:26
From UK
Group:
Registered Users
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 ;
}
Then,
./ myProgram > out *> out
Results in:
main . exe : unable to open redirection file
See also:
https://eab.abime.net/showthread.php?t=100148
If liberty means anything at all, it means the right to tell people what they do not want to hear. George Orwell.
Re: Redirect STDERR and STDOUT to the same file
Posted on:
2023/4/9 20:26
#2
Home away from home
Joined: 2006/12/1 19:07Last Login
: Yesterday 15:39
From Germany
Group:
Registered Users
@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".
Re: Redirect STDERR and STDOUT to the same file
Posted on:
2023/6/11 14:58
#3
Quite a regular
Joined: 2021/12/20 2:52Last Login
: Yesterday 23:26
From UK
Group:
Registered Users
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:
#include <proto/dos.h>
BPTR _stdout , _stderr ;
int ret = 0 ;
int main ()
{
_stdout = IDOS -> Open ( "_stdout" , MODE_NEWFILE );
_stderr =
#if 0
* IDOS -> Open ( "_stderr" , MODE_NEWFILE )
#else
_stdout
#endif
;
if(!( _stdout && _stderr ))
{
ret = 10 ;
goto ENDER ;
}
( void ) IDOS -> SystemTags ( "dir NOTEXISTS" , SYS_Output , _stdout , SYS_Error , _stderr , TAG_END );
ENDER :
if( _stdout )
{
IDOS -> FClose ( _stdout );
if( _stdout == _stderr )
{
_stderr = _stdout =( BPTR ) 0 ;
}
else
{
_stdout =( BPTR ) 0 ;
}
}
if( _stderr ) { IDOS -> FClose ( _stderr ); _stderr =( BPTR ) 0 ; }
return ret ;
}
This program invokes a DIR on some non-existent file. That always results in some text to both STDOUT and STDERR.
You will see that when you run this program both STDOUT and STDERR are in the same file.
I am surprised no one else has run into this issue since redirection from both of this FDs into a single location is fairly usual.
I guess - at the least - I could upload a similar "tool" to handle such a situation.
If liberty means anything at all, it means the right to tell people what they do not want to hear. George Orwell.
Re: Redirect STDERR and STDOUT to the same file
Posted on:
2023/6/11 21:26
#4
Just can't stay away
Joined: 2006/12/1 18:01Last Login
: Yesterday 22:24
From Copenhagen, Denmark
Group:
Registered Users
@rjd324 Have you tried this? dir xx >> RAM:p *>> RAM:p Works for me. Best regards, Niels
Re: Redirect STDERR and STDOUT to the same file
Posted on:
2023/6/11 21:29
#5
Quite a regular
Joined: 2021/12/20 2:52Last Login
: Yesterday 23:26
From UK
Group:
Registered Users
@nbache
Thanks, it "kind of" work. For some reason the STDOUT portion is truncated and says, for example:
ormation for bb
instead of:
Could not get information for bb
On top of which, I do not see why you would need that syntax.
Why append? This is not what I would have expected.
But, thanks - you almost got us there.
===
Perhaps only appending one of them would work. The test program I wrote above does it correctly - so why cannot Shell?
Is this some sort of bug?
If liberty means anything at all, it means the right to tell people what they do not want to hear. George Orwell.
Re: Redirect STDERR and STDOUT to the same file
Posted on:
2023/6/11 22:46
#6
Just can't stay away
Joined: 2006/12/1 18:01Last Login
: Yesterday 22:24
From Copenhagen, Denmark
Group:
Registered Users
@rjd324
I can't reproduce your truncation:
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.
But I'm guessing.
Best regards,
Niels
Re: Redirect STDERR and STDOUT to the same file
Posted on:
2023/6/11 23:04
#7
Quite a regular
Joined: 2021/12/20 2:52Last Login
: Yesterday 23:26
From UK
Group:
Registered Users
Perhaps you cannot reproduce it because you are not using the Enhancer version 54.5. @cnicol It looks like when I use the classic version 53.3 I see that the output looks reasonable. When I use 54.5 I get the truncation I talked about.
If liberty means anything at all, it means the right to tell people what they do not want to hear. George Orwell.
Re: Redirect STDERR and STDOUT to the same file
Posted on:
2023/6/11 23:08
#8
Quite a regular
Joined: 2021/12/20 2:52Last Login
: Yesterday 23:26
From UK
Group:
Registered Users
Truncation also seems to occur for version LIST 54.15 versus 53.10.
If liberty means anything at all, it means the right to tell people what they do not want to hear. George Orwell.
Re: Redirect STDERR and STDOUT to the same file
Posted on:
2023/6/12 7:53
#9
Home away from home
Joined: 2006/12/4 23:15Last Login
: 5/8 10:56
Group:
Registered Users
The core problem with using the syntax
Command >ram:log *>>ram:log
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.
To expand your simple test above.
#include <stdio.h>
int main ()
{
fprintf ( stdout , "STDOUT1\n" );
fflush ( stdout );
fprintf ( stderr , "STDERR1\n" );
fflush ( stderr );
fprintf ( stdout , "STDOUT2\n" );
fflush ( stdout );
fprintf ( stderr , "STDERR2\n" );
fflush ( stderr );
fprintf ( stdout , "STDOUT3\n" );
fflush ( stdout );
return 0 ;
}
9.AmigaOS4 :> gcc - o ram : testit test . c
9.AmigaOS4 :> ram : testit > RAM : LOG *>> RAM : LOG
9.AmigaOS4 :> type ram : LOG
STDERR1
STDERR2
STDOUT3
You need to redirect stderr to stdouts stream. Not 100% sure if you can do that at the shell level.
Historicaly in AmigaDOS pre AmigaOS 4 shells STDERR and STDOUT were the same stream so no extra sysntax would be needed.
Anonymous
Re: Redirect STDERR and STDOUT to the same file
@rjd324
I had a similar problem when automating the logs from scummvm compilations.
Some stuff still ended up in shell instead of the log file (or was partly overwritten too)
What I did was to write to two different log files and merge them after the compilation/command is done.
Command >ram:1st.log *>ram:2nd.log
Type ram:2nd.log >> ram:1st.log
Probably not exactly what you're looking for, but maybe enough to move on?
Re: Redirect STDERR and STDOUT to the same file
Posted on:
2023/6/12 9:07
#11
Quite a regular
Joined: 2021/12/20 2:52Last Login
: Yesterday 23:26
From UK
Group:
Registered Users
@Raziel
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.
Re: Redirect STDERR and STDOUT to the same file
Posted on:
2023/6/12 9:25
#12
Home away from home
Joined: 2006/12/4 23:15Last Login
: 5/8 10:56
Group:
Registered Users
"&>"
Don't name it that
Weirldy named commands will only cause issues.
Re: Redirect STDERR and STDOUT to the same file
Posted on:
2023/6/12 9:39
#13
Home away from home
Joined: 2006/12/4 23:15Last Login
: 5/8 10:56
Group:
Registered Users
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.
Re: Redirect STDERR and STDOUT to the same file
Posted on:
2023/6/12 9:49
#14
Home away from home
Joined: 2006/12/4 23:15Last Login
: 5/8 10:56
Group:
Registered Users
Instead of writing a program why not just wrap yout command in an abc-shel call sh -c "testit 2>&1" >raM:log
Re: Redirect STDERR and STDOUT to the same file
Posted on:
2023/6/12 10:42
#15
Quite a regular
Joined: 2021/12/20 2:52Last Login
: Yesterday 23:26
From UK
Group:
Registered Users
@broadblues Of course the name was a joke. A reference to the shorthand &> that you can do in Linux, even though I always explicitly perform 1> 2>&1. This program was just a little test anyway. You are right, I will mess around with PIPES and see what happens. Using "sh" is not the point. I am talking about native DOS. Anyway, thanks for the tips. --- But then again AmigaOS is not Linux and not POSIX...
Edited by rjd324 on 2023/6/12 11:01:06
If liberty means anything at all, it means the right to tell people what they do not want to hear. George Orwell.
Re: Redirect STDERR and STDOUT to the same file
Posted on:
2023/6/12 14:12
#16
Just popping in
Joined: 2022/12/3 9:30Last Login
: 2023/6/21 21:25
From Nicolakakis
Group:
Registered Users
@rjd324 I have reproduced the truncation issue with both Dir 54.7 and List 54.18. It shouldn't be hard to fix. Thanks for pointing it out. Costas.
Re: Redirect STDERR and STDOUT to the same file
Posted on:
2023/6/12 21:39
#17
Just can't stay away
Joined: 2006/12/1 18:01Last Login
: Yesterday 22:24
From Copenhagen, Denmark
Group:
Registered Users
@rjd324
Quote:
Perhaps you cannot reproduce it because you are not using the Enhancer version 54.5. That's correct, I don't.
Well, you know where to go with that one, then.
Edit: Ah, I see Costas is already on it
.
Best regards,
Niels
Re: Redirect STDERR and STDOUT to the same file
Posted on:
2024/7/17 16:39
#18
Just can't stay away
Joined: 2009/10/7 0:11Last Login
: 3/3 11:42
From Odense
Group:
Registered Users
@broadblues
Quote:
sh -c "testit 2>&1" >raM:log Doing this type of syntax in a shell sure works out. For simple cases.
This is a line from toolchain.prf in qmake :
Quote:
output = $$system("$$cmd_prefix $$QMAKE_CXX $$qtMakeExpand($$cxx_flags) -xc++ - 2>&1 $$cmd_suffix", lines, ec)This proves to be intensely problematic, because of a) the environment prefix (cmd_prefix) and b) the way quotes are used. Or maybe I am just stupid.
Some way of emulating 2>&1 would be preferable.
Currently Active Users Viewing This Thread:
1
(
0 members
and 1 Anonymous Users
)