Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

farmerdoug

macrumors 6502a
Original poster
Sep 16, 2008
541
0
If grep fails to find a file it prints out an error message. Neither redirecting the output of grep
Code:
 strcpy(grep, "grep        \"");
            strcat(grep, date2[d]);
            strcat(grep, ",1552\" ");
            strcat(grep, dir);
            strcat(grep, &ratios[i*pagesize]);
            strcat(grep, ".txt > \"out.txt\"");
            corncob = popen(grep, "r");
            fgets(buf,100,corncob);
            pclose(corncob);

nor redirecting the output of the program

./code > "out.txt"

gets me a list of the files it can't find. Any suggestions on how to do that?
 
not grep part 2

If I use ls file | wc, I can tell if the file exists. How do I get the values out of wc?
 
Is your goal to redirect those grep error messages (about the fact that it can't find certain files) to another file? The standard redirect symbol ( > ) with nothing else only redirects stuff sent to the standard output stream. Error messages (like messages about the fact that grep can't find a certain file) are sent to the standard error stream and are redirected differently.

Here are a few examples:

Redirect normal results and errors:
Code:
grep foo bar > results_and_errors.txt 2>&1

A simplified version of the above command is (which may not work on all types of shells):
Code:
grep foo bar >& results_and_errors.txt

Redirect errors only:
Code:
grep foo bar 2> errors_only.txt

The "Redirection (computing)" wikipedia article has a lot of good info about this. I hope this is what you were asking.
 
I search google but didn't think to search redirection.
Method 3 worked for me.
Thanks
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.