How to redirect gcc errors to a file in Unix?
-
12-11-2019 - |
Question
I tried following this but that doesn't work in Unix.
I've been running this command :
gcc temp.c -o temp.o 2> err.txt
And got the following error:
gcc: 2: No such file or directory
Any ideas what that shouldn't work? Maybe because I’m using it over a Unix server?
Solution
In tcsh
you don't use 2>
to redirect stderr, you use >&
that will redirect both stdout and stderr. If you want to redirect them separately, have a look at this quick guide.
OTHER TIPS
Redirecting stderr using 2>
in tsch is not possible, but here are 2 work arounds
bash -c "gcc temp.c -o temp.o 2> err.txt" #if bash or sh is available
(gcc temp.c -o temp.o > /dev/null) > & err.txt
Yours:
gcc temp.c -o temp.o 2> err.txt
you sure mean:
gcc -o temp.o temp.c 2> err
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow