Index: trunk/psModules/src/detrend/pmDetrendDB.c
===================================================================
--- trunk/psModules/src/detrend/pmDetrendDB.c	(revision 7589)
+++ trunk/psModules/src/detrend/pmDetrendDB.c	(revision 7770)
@@ -85,23 +85,34 @@
 pmDetrendSelectResults *pmDetrendSelect (pmDetrendSelectOptions *options)
 {
-
-    char answer[128];
-    char line[1024];
+    bool status;
+    char *line = NULL;
 
     char *time = psTimeToISO (&options->time);
     char *type = pmDetrendTypeToString (options->type);
 
-    sprintf (line, "detselect -camera %s -time %s -type %s",
-             options->camera, time, type);
+    // generate the detselect command
+    psStringAppend (&line, "detselect -camera %s -time %s -type %s", options->camera, time, type);
     psFree (time);
     psFree (type);
 
-    // XXX put this in a fork/exec to catch the timeout
-    FILE *p = popen (line, "r");
-    fgets (answer, 127, p);
-    pclose (p);
+    // use psPipe to exec the command, wait for response
+    psIOBuffer *buffer = psIOBufferAlloc (512);
+    psPipe *pipe = psPipeOpen (line);
+    status = psIOBufferReadEmpty (buffer, 100, pipe->stdout);
+    if (!status) {
+        psError (PS_ERR_IO, false, "detselect is not responding");
+        psFree (buffer);
+        psFree (pipe);
+        psFree (line);
+        return NULL;
+    }
+    psPipeClose (pipe);
+    psFree (pipe);
+    psFree (line);
 
-    psList *list = psStringSplit (answer, " ", false);
-    psArray *array = psListToArray (list);
+    // XXX need to parse the response more robustly
+    // XXX for now, assume a single line
+    psArray *array = psStringSplitArray (buffer->data, " ", false);
+    psFree (buffer);
 
     if (!array)
@@ -121,6 +132,4 @@
 
     psFree (array);
-    psFree (list);
-
     return results;
 }
@@ -130,17 +139,29 @@
 char *pmDetrendFile (char *detID, char *classID)
 {
+    bool status;
+    char *line = NULL;
 
-    char answer[128];
-    char line[1024];
+    // generate the detselect command
+    psStringAppend (&line, "detselect -select -detID %s -classID %s", detID, classID);
 
-    sprintf (line, "detselect -select -detID %s -classID %s", detID, classID);
+    // use psPipe to exec the command, wait for response
+    psIOBuffer *buffer = psIOBufferAlloc (512);
+    psPipe *pipe = psPipeOpen (line);
+    status = psIOBufferReadEmpty (buffer, 100, pipe->stdout);
+    if (!status) {
+        psError (PS_ERR_IO, false, "detselect is not responding");
+        psFree (buffer);
+        psFree (pipe);
+        psFree (line);
+        return NULL;
+    }
+    psPipeClose (pipe);
+    psFree (pipe);
+    psFree (line);
 
-    // XXX put this in a fork/exec to catch the timeout
-    FILE *p = popen (line, "r");
-    fgets (answer, 127, p);
-    pclose (p);
-
-    psList *list = psStringSplit (answer, " ", false);
-    psArray *array = psListToArray (list);
+    // XXX need to parse the response more robustly
+    // XXX for now, assume a single line
+    psArray *array = psStringSplitArray (buffer->data, " ", false);
+    psFree (buffer);
 
     if (!array)
@@ -154,6 +175,4 @@
 
     psFree (array);
-    psFree (list);
-
     return result;
 }
