Re: Capture unix command shell output to a buffer

From: Barry Margolin (barmar_at_alum.mit.edu)
Date: 01/03/05

  • Next message: Norman L. DeForest: "Re: C-R Systems (Spam Filter)"
    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 ***
    

  • Next message: Norman L. DeForest: "Re: C-R Systems (Spam Filter)"

    Relevant Pages

    • RE: Query Problem, Please Help!!
      ... > this table to be laid out the way it is. ... The reason that experts recommend using a query as the Record Source for a ... The query ... will allow the designer to display the data in just about any way needed. ...
      (microsoft.public.access.queries)
    • Re: Usenet/News -> web/book/etc. (was: XNA redux)
      ... I'm still pretty sure it's so that Google Groups won't display the ... How is it to the advantage or aid of the XNAposter for GG to display ... transient ephemeral medium with no organised archiving of most groups. ... The reason that gmane refers to the XNA as 'obsolescent' is because gmane ...
      (news.software.readers)
    • Re: Parking appeal question (long).
      ... Common sense prevailed and mate was sent on his way. ... In this case the council are obliged to display a sign at the ... my windscreen (for whatever reason) then I'd put my hands up. ...
      (uk.legal)
    • Re: Google Earth out
      ... >> with several seriously incomprehensible icons (where playing around to ... >> a larger display area. ... > Some of this is due to Google's business -- it's the same reason why ... > there's so much junk around the results of a Google search. ...
      (comp.sys.mac.apps)
    • Re: 1080p...and why did I?
      ... fields and 30 frames per second. ... That's a good reason to have 1080p capability in a display. ... drive since not so much programming in that format is likely (mostly only ...
      (alt.tv.tech.hdtv)