Bug 997

Summary: HUSH: redirecting output of the last line of "printf" does not work
Product: Busybox Reporter: Mikel Garai <m.garai>
Component: OtherAssignee: unassigned
Status: RESOLVED WORKSFORME    
Severity: minor CC: busybox-cvs
Priority: P5    
Version: 1.15.x   
Target Milestone: ---   
Hardware: Other   
OS: Linux   
Host: Target:
Build:

Description Mikel Garai 2010-01-27 15:10:00 UTC
architecture: bfin
version: 1.15

(can not reproduce on pc even with BUILD_AS_NOMMU set to 1)

The following command:
printf line > testfile.txt

In hush prints "line" to the console and leaves testfile.txt void
In bash testfile.txt contains "line"

The command:
printf "line1\nline2" > testfile.txt

In hush prints "line2" to the console and testfile.txt contains "line1"
In bash "line1\n"line2" is written to testfile.txt

thanks in advance,

Mikel Garai
Comment 1 Mikel Garai 2010-01-27 15:10:55 UTC
I forgot to say that the command:

printf line | cat > file.txt


does the right thing writting "line" to file.txt
Comment 2 Denys Vlasenko 2010-01-27 22:30:44 UTC
Does it help if you add a fflush(NULL) in hush.c like this:

static int run_applet_main(char **argv, int (*applet_main_func)(int argc, char **argv))
{
        int argc = 0;
        while (*argv) {
                argc++;
                argv++;
        }
-       return applet_main_func(argc, argv - argc);
+       argc = applet_main_func(argc, argv - argc);
+       fflush(NULL);
+       return argc;
}
Comment 3 Denys Vlasenko 2010-02-02 00:07:04 UTC
Any news?
Comment 4 Mikel Garai 2010-02-03 16:30:39 UTC
I did not have any time to test it jet, because the patch is not applicable to the version of busybox that I am using (1.15.3, that has no function called run_applet_main in hush.c), and it takes some time to set up everything to test other version.

Anyway I will try it ASAP, that could be more time than I would like to be.

Thanks, 

Mikel
Comment 5 Denys Vlasenko 2010-02-22 09:27:29 UTC
Any news?
Comment 6 Mikel Garai 2010-02-22 11:30:34 UTC
I just tested the unstable busybox's hush (1.16.0) and worked well without the patch, so I did not even try to apply it.

Thank you very much and sorry for taking so much time to test it,


Mikel Garai