Ok, so the gotcha with options 1 - 3 is that you have closed the system call after trying to read from the newly created file. This means that for all intents and purposes, the new file
has yet to be created or created fully were it large.
So solution to all of them is:
print result > "file1" # file1 is the input for the external program
system("program file1 file2 [options]") # file2 is the output of the external program
close("program file1 file2 [options]") # must close call here if you are going to reuse any of the files
while ((getline var < "file2") > 0) # use file2 do work on it
close("program file1 file2 [options]")
As for option 4, I think you need to first consider how you would perform the same task on the command line with your program with the following 2 criteria:
1. The program receives data from stdin, probably via a pipe
2. The output of the program is sent to stdout, ie the screen
This would negate the need for either file1 or file2 in the code which is where option 4 comes in, ie it gets the data from awk and transfers the output of the command back to awk.