Reading output from a .sh script in C+


pmprog

DNF (Did Not Finish)
Joined
Apr 25, 2011
Messages
4,150
I'm working on my USB Mass Storage plugin. I've modified the op_storage.sh script file to allow the device to be passed as a parameter. I also added a "list" parameter that returns the same data usually sent into zenity for the user's selection.


I'm trying to read this into my plugin so I can create submenus. This is what I have, is there a better way to do this? ie without a temp file



Code:
  system("/usr/share/configbutton/usbmass.sh list >/tmp/usbops");

  fp = fopen("/tmp/usbops", "r");

  if (fp != NULL) {

   while( fscanf(fp, "%s", opPath) > 0 )

   {

    // TODO: Create menu

   }

   fclose(fp);

  }


Cheers
 
Isn't it possible to store the output in an envvar instead of a tempfile and read it with getenv afterwards?
 
Last edited by a moderator:
Cheers guys, looks like popen should do the job
 
Back
Top