How to redirect the output of lbb_main function to variable on c program

Martin Lewis martin.lewis.x84 at
Wed Jun 3 07:34:43 UTC 2020


Sounds like you need output redirection.
You need to create a pipe, dup2 it over stdout, call lbb_main, and
read the output from
the pipe.

Similar question:


On 22/05/2020, Tiago Araujo da costa <tiagoarcosta at> wrote:
> I build and put on /usr/local/lib. In addition, I
> created a symbolic link /usr/local/lib/libbusybox.soI have a file, the
> content of which is:
> $ cat ogt.cextern int lbb_main(char **argv);
> int main()
> {
>     char* strarray[] = {"ifconfig",0};
>     lbb_main(strarray);
>     return 1;
> }
> I compile the above file with the following command:
> $ gcc -o ogt ogt.c -lbusybox
> And run:
> $ ./ogteth0      Link encap:Ethernet  HWaddr 07:1F:EA:C9:3B:4C
>           inet addr:  Bcast:  Mask:
>           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
>           RX packets:7989695 errors:0 dropped:258 overruns:0 frame:0
>           TX packets:4696710 errors:0 dropped:0 overruns:0 carrier:0
>           collisions:0 txqueuelen:1000
>           RX bytes:2659885363 (2.4 GiB)  TX bytes:7111442553 (6.6 GiB)
> lo        Link encap:Local Loopback
>           inet addr:  Mask:
>           UP LOOPBACK RUNNING  MTU:65536  Metric:1
>           RX packets:2654 errors:0 dropped:0 overruns:0 frame:0
>           TX packets:2654 errors:0 dropped:0 overruns:0 carrier:0
>           collisions:0 txqueuelen:1000
>           RX bytes:225192 (219.9 KiB)  TX bytes:225192 (219.9 KiB)
> How do I redirect the output of command "lbb_main (strarray);" for a
> variable, inside the ogt.c program?

More information about the busybox mailing list