MCPcopy Create free account
hub / github.com/apache/cloudberry / pipe_read_line

Function pipe_read_line

src/common/exec.c:362–393  ·  view source on GitHub ↗

* Execute a command in a pipe and read the first line from it. */

Source from the content-addressed store, hash-verified

360 * Execute a command in a pipe and read the first line from it.
361 */
362char *
363pipe_read_line(char *cmd, char *line, int maxsize)
364{
365 FILE *pgver;
366
367 /* flush output buffers in case popen does not... */
368 fflush(stdout);
369 fflush(stderr);
370
371 errno = 0;
372 if ((pgver = popen(cmd, "r")) == NULL)
373 {
374 perror("popen failure");
375 return NULL;
376 }
377
378 errno = 0;
379 if (fgets(line, maxsize, pgver) == NULL)
380 {
381 if (feof(pgver))
382 fprintf(stderr, "no data was returned by command \"%s\"\n", cmd);
383 else
384 perror("fgets failure");
385 pclose(pgver); /* no error checking */
386 return NULL;
387 }
388
389 if (pclose_check(pgver))
390 return NULL;
391
392 return line;
393}
394
395
396/*

Callers 3

find_other_execFunction · 0.85
getRestoreCommandFunction · 0.85
check_execFunction · 0.85

Calls 1

pclose_checkFunction · 0.85

Tested by

no test coverage detected