Re: Capture unix command shell output to a buffer
From: Barry Margolin (barmar_at_alum.mit.edu)
Date: 01/03/05
- Previous message: New User: "Re: Capture unix command shell output to a buffer"
- In reply to: New User: "Re: Capture unix command shell output to a buffer"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 02 Jan 2005 23:46:15 -0500
In article <1104180897.376255.286170@f14g2000cwb.googlegroups.com>,
"New User" <webcontacts00@yahoo.com> wrote:
> Hi,
>
> I tried this:
>
> FILE *fp;
> char cmd[10];
> zero(cmd); // metset cmd buffer to 0x0
> strcpy(cmd, "ls -al");
> char cmd_result[1000];
> zero(cmd_result); // memset cmd_result to 0x0
>
> fp = popen(cmd, "r");
>
> while (fgets(cmd_result, sizeof(cmd_result), fp))
> {
> printf("%s", cmd_result);
> }
>
> pclose(fp);
>
> But when I display cmd_result, it only shows the last line of the
> command output.. .. any idea why?
>
> Thanks,
> Shaival
Didn't you post this same code excerpt a few days ago? Did you repost
it for some reason, or is something resurrecting old posts automatically?
-- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me ***
- Previous message: New User: "Re: Capture unix command shell output to a buffer"
- In reply to: New User: "Re: Capture unix command shell output to a buffer"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|