Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Where to find resource on "how to analyze " system call output

Where to find resource on "how to analyze " system call output

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestionlearning
3 Posts 3 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I like to bypass some of the Bluetooth "resources" in my C / C++ code by using (direct) system calls. I can czech for return value, but like to analyze more of the output, in including errors. Where do I start ? Contrary to my opinion ( about RTFM ) - can somebody give me link to "RTFM" how to do it ?

    system(" hcitool dev");

    return to stdout (?)

    Devices:
    hci1 00:50:B6:80:4D:5D
    hci0 00:15:83:15:A2:CB

    K 1 Reply Last reply
    0
    • L Lost User

      I like to bypass some of the Bluetooth "resources" in my C / C++ code by using (direct) system calls. I can czech for return value, but like to analyze more of the output, in including errors. Where do I start ? Contrary to my opinion ( about RTFM ) - can somebody give me link to "RTFM" how to do it ?

      system(" hcitool dev");

      return to stdout (?)

      Devices:
      hci1 00:50:B6:80:4D:5D
      hci0 00:15:83:15:A2:CB

      K Offline
      K Offline
      k5054
      wrote on last edited by
      #2

      Rather than system(), you want to use popen(). The only problem is that popen() doesn't supply a separate FILE for stderr, so you have to use output redirection to capture both e.g.

      FILE *cmd = popen("hcitool dev 2>&1", "r");

      char *buffer = NULL;
      size_t len = 0;
      ssize_t readlen;
      while ( (readlen = getline(&buffer, len, cmd)) > 0)
      {
      /* process input buffer */
      }
      free(buffer);
      pclose(cmd);

      You could perhaps also use output redirection to capture output separately e.g.

      FILE *cmd = popen("hcitool dev 2>/tmp/hcierrs", "r");
      /* process input as above */
      FILE *cmd_errs = fopen("/tmp/hcierrs", "r");
      /* loop through input from cmd_errs ... */
      unlink("/tmp/hcierrs");

      If you're going to do that, you might want to look at creating unique temporary file names, so that you don't clobber output if you happen to have more than one instance of the program running at the same time. mkstemp() can help you here. For the really advanced, you might look into trying "roll your own" version of popen that uses fork() and one of the exec() functions to separate out stdout and stderr to two separate FILES.

      Keep Calm and Carry On

      N 1 Reply Last reply
      0
      • K k5054

        Rather than system(), you want to use popen(). The only problem is that popen() doesn't supply a separate FILE for stderr, so you have to use output redirection to capture both e.g.

        FILE *cmd = popen("hcitool dev 2>&1", "r");

        char *buffer = NULL;
        size_t len = 0;
        ssize_t readlen;
        while ( (readlen = getline(&buffer, len, cmd)) > 0)
        {
        /* process input buffer */
        }
        free(buffer);
        pclose(cmd);

        You could perhaps also use output redirection to capture output separately e.g.

        FILE *cmd = popen("hcitool dev 2>/tmp/hcierrs", "r");
        /* process input as above */
        FILE *cmd_errs = fopen("/tmp/hcierrs", "r");
        /* loop through input from cmd_errs ... */
        unlink("/tmp/hcierrs");

        If you're going to do that, you might want to look at creating unique temporary file names, so that you don't clobber output if you happen to have more than one instance of the program running at the same time. mkstemp() can help you here. For the really advanced, you might look into trying "roll your own" version of popen that uses fork() and one of the exec() functions to separate out stdout and stderr to two separate FILES.

        Keep Calm and Carry On

        N Offline
        N Offline
        nikimiles
        wrote on last edited by
        #3

        What is a software development company? Software development is a process where software is developed for real-time use from start to finish. Software development is used by many companies around the globe to put together software solutions that make their business run as smoothly as possible. Software development companies can help companies develop everything from custom software applications for mobile and web applications to custom software solutions for enterprise, e-commerce, and web-based business. Some of the worlds biggest companies even depend on the experience of dedicated software development companies to develop software and apps for their mobile and web applications and for their enterprise, e-commerce, and web-based business. I recommend you contact syndicode.com

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups