문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top