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

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


Hello,

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:
https://stackoverflow.com/questions/17071702/c-language-read-from-stdout

Martin

On 22/05/2020, Tiago Araujo da costa <tiagoarcosta at yahoo.com.br> wrote:
> I build libbusybox.so.1.31.1 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:172.16.51.62  Bcast:172.16.51.255  Mask:255.255.255.0
>           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:127.0.0.1  Mask:255.0.0.0
>           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