I am wondering how I might read shell output straight into a variable. (I have a GUI where I need to display some values such as temperature etc. that I can grab with a shell command). For the sake of example, let’s say I want to display seconds of the current time which I can get from the “date” command. For the time being, I would do that by having the shell write the number into a temporary file and then read the number from that file before removing the file again. This works, but it leaves me with the nagging feeling that it is probably not the most efficient way of doing it. Is there a better way? How have others solved this problem?
Running this and the first version (without the rm) 10000 times, I measure the following times:
gSystem->OpenPipe: Real time 0:01:54, CP time 15.340
gSystem->Exec() with tmp file: Real time 0:02:35, CP time 15.450
A noticeable, but not enormous speed up.