In a main process I create a child process which runs a converter. The result of the converter normally outputs to the screen. This result has to be redirected to a file is some directory. Normally you should run following command: progname file2 > file3. In a main console no problem. Giving this command to a child process progname considers instead of 1 parameter three parameters [1] file2 [2] > [3] file3 and gives the error to many parameters as it expects only one.
The code below a bit abstract, but as it is company I can not give all code, will try to shorten a set only the essentials.:
Open FILE * out for “w”
Dup2(out,1)
Start program in fork() /in child process close(out)
Wait(child finish)s
The result is that the file is created, output comes to screen and the file stays empty.



LinkBack URL
About LinkBacks



