bash - C: execlp() and > -
i want run execlp() c file , write result output file. use line:
buff = "./cgi-bin/smth"; execlp(buff, buff, "> /cgi-bin/tmp", null);
where smth compiled c script. smth prints stdout, , no file appears. happens, , how put script result output file?
you have handle dup2
if using execlp
. can @ how handle file out execvp
in comparison. pass flag out redirection , handle it:
if (structpipeline->option[0] == 1) { /* output redirection */ int length = structpipeline[i].size; char *filename = structpipeline->data[length - 1]; (int k = length - 2; k < length; k++) structpipeline->data[k] = '\0'; fd[1] = open(filename, o_wronly | o_creat, 0666); dup2(fd[1], stdout_fileno); close(fd[1]); } /* todo: input redirection */ execvp(structpipeline[i].data[0], structpipeline[i].data);
see question redirecting exec output buffer or file
Comments
Post a Comment