+ if (i == 0)//return if block and command output are both empty
+ return;
+ if (delim[0] != '\0') {
+ //only chop off newline if one is present at the end
+ i = output[i-1] == '\n' ? i-1 : i;
+ strncpy(output+i, delim, delimLen);
+ }
+ else
+ output[i++] = '\0';