0

I'm trying to write standard out and standard error to the same file.

$ /usr/local/bin/aapt dump badging base.apk 1>sout.text 2>serror.text

$ dog sout.text
package: name='foo' versionCode='1' versionName='1.0'
sdkVersion:'21'
targetSdkVersion:'33'
uses-permission:'android.permission.INTERNET'

[...]

application: label='foo' icon='res/ic_launcher.png'
launchable-activity: name='foo.splash.SplashActivity'  label='' icon=''

$ dog serror.text
W/ResourceType( 9708): Failure getting entry for 0x7f0802a8 (t=7 e=680) in package 0 (error -75)
ERROR getting 'android:icon' attribute: attribute is not a string value

Writing them to separate files (as shown above) works fine. Without redirection, all output above appears on the terminal (with the error messages at the bottom).

According to the bash man page, any of the following should combine standard output and standard error in the same file:

$ /usr/local/bin/aapt dump badging base.apk &> soutandserror.text

$ /usr/local/bin/aapt dump badging base.apk >soutanderror.text 2>&1

$ /usr/local/bin/aapt dump badging base.apk 1>soutanderror.text 2>soutanderror.text

All of the above produce a file with only the output (and no error messages).

Can someone explain why the methods shown in the man page don't work, and how to do this redirection? Thank you in advance.

2
  • 2
    (1) Maybe these times there were no errors. How do you know? (2) Do not use 1>soutanderror.text 2>soutanderror.text for writing to the same regular file. This syntax opens the file twice, each instance will use its own writing position. In effect data written to stderr will overwrite data written to stdout (and/or the other way around, depending on the sequence of writes, their timing, buffering and such). For comparison: 2>&1 duplicates the descriptor, there will be a common writing position, this is the right way. Commented Jun 5 at 14:36
  • It has to exist first to >> append. touch stdio_log.text; /usr/local/bin/aapt dump badging base.apk 1>>stdio_log.text 2>>stdio_log.text, but Kamil's right, 2>&1 is proper.
    – JayCravens
    Commented Jun 5 at 14:55

0

You must log in to answer this question.

Browse other questions tagged .