What about:
./file_cleanse <file1.txt> > /tmp/temporaryFile
./file_operation <temp.txt> < /tmp/temporaryFile
Вопрос
I have a C program which takes a file as an argument, cleans up the file and writes the cleansed data to a new temp file. It then accepts some stdin, cleans it up and sends it stdout.
I have a second file which performs operations on this temp file and on the stdin again.
./file_cleanse <file1.txt> | ./file_operation <temp.txt>
I either get no or nonsensical stdout from the ./file_operation and I believe this is because it is reading from a file that's still being written/doesn't exist at this point.
Is there any way to make ./file_operation wait until ./file_cleanse has returned a value in bash?
Решение
What about:
./file_cleanse <file1.txt> > /tmp/temporaryFile
./file_operation <temp.txt> < /tmp/temporaryFile
Другие советы
As I understand the question, file_operation
needs to read the standard output of file_cleanse
after processing the temporary file, but it should not process the temporary file until file_cleanse
has written some data to its standard output (the standard input of file_operation
).
If that's correct, then a simple synchronization is for file_operation
to read (a byte or any convenient larger amount of data) from its standard input. When this is successful, the file_cleanse
must have finished with the temporary file; file_operation
can therefore process the temporary file, and then read the rest of its standard input and process that appropriately.