trying to capture javac output in bash shell - bash

I'm trying to redirect the java compiler output to a file.
I thought it's supposed to be:
javac file.java > log.txt
or something. Instead, I see all the output on the terminal and nothing in log.txt!
Also, if I want to log errors too, do I do
javac file.java 2>&1 > log.txt
?

javac file.java 2> log.txt
The reason is that you have two output file descriptors instead of one. The usual one is stdout, which you can redirect with > and it's supposed to be used for resulting output. The second one, stderr, is meant for human readable output like warnings, errors, current status etc., this one is redirected with 2>.
Your second line, using 2>&1, redirects stderr to stdout and finally stdout into log.txt.

Have you tried
javac -Xstdout log.txt file.java
This will send compiler errors to a log file instead of stderr.

Related

Pipe direct tty output to sed

I have a script using for a building a program that I redirect to sed to highlight errors and such during the build.
This works great, but the problem is at the end of this build script it starts an application which usually writes to the terminal, but stdout and stderr redirection doesn't seem to capture it. I'm not exactly sure how this output gets printed and it's kind of complicated to figure out.
buildAndStartApp # everything outputs correctly
buildAndStartApp 2>&1 | colorize # Catches build output, but not server output
Is there any way to capture all terminal output? The "script" command catches everything, but I would like the output to still print to my terminal rather than redirecting to a file.
I found out script has a -c option which runs a command and all of the output is printed to stdout as well as to a file.
My command ended up being:
script -c "buildAndStartApp" /dev/null | colorize
First, when you use script, the output does still go to the terminal (as well as redirecting to the file). You could do something like this in a second window to see the colorized output live:
tail -f typescript | colorize
Second, if the output of a command is going to the terminal even though you have both stdout and stderr redirected, it's possible that the command is writing directly to /dev/tty, in which case something like script that uses a pseudo-terminal is the only thing that will work.

Duplicating stderr compilation output into separate file

I have a project, which builds by using make, and I want to add possibility
to analyze overall state of warning messages.
My idea is change make rules in order to duplicate stderr compilation output into separate file during full rebuild. Means each time make all will be done, all output will be printed in console and in addition stderr output will be duplicating into separate file.
This warning report file will be added into repository, so that I will have possibility to compare warnings existing in repository and local warnings.
The question is how to DUPLICATE (not redirect) stderr output into separate file? Means how I should change all target in Makefile?
I know how to redirect stderr output (make all 2>warning_report.txt), but it is not
what I need. Warning messages should be both in main console output and in warning file.
I use Windows 7 as work environment but I had no any deal with Windows command line or batch files before.
Thanks in advance.
Edited:
In my case final solution looks like below:
make all 3>&1 1>&2- 2>&3- | tee.bat warning_report.txt
In this case script tee.bat, which is written in JScript for Windows, I took from link specified by PA (thanks).
What about swapping, I took it from here and here.
I don't know about windows but you can do it using tee command in Linux. tee is used to redirect STDOUT to file as well as console so you can take its advantage and check if you can solve your problem.
make all 2>&1 1>stdout.log | tee stderr.log
redirect STDERR to STDOUT, redirect STDOUT to stdout.log and all the STDERR is copied to stderr.log ans echoed on the console as well.
But the solution is not complete yet. The STDOUT is not printed on the console but only copied to the stdout.log. Try playing around the commands you will get the solution .
I just re-read your question and decided I would try to answer it.
Here's a snippet made to export stderr and display it.
#echo off
if exist stderr.error del stderr.error
this_is_not_a_command 2>stderr.error
if exist stderr.error type stderr.error & del stderr.error
This would export stderr to a file and then display the contents of that file.
Hope that helps.

How to capture dvdauthor output to file

I'm trying to capture dvdauthor's output to a file.
So far i found this command but it's not working:S
dvdauthor -x dvdauthor.xml > output.txt
Any kind of idea is really appreciated.
It looks as though dvdauthor prints a lot of output to stderr rather than stdout. I don't have this software myself and so can't be sure but I see a lot of this in (what I presume to be) the source code, which suggests that it's printing informational messages to stderr rather than stdout:
fprintf(stderr, "INFO: dvdauthor creating table of contents\n");
The > redirect will only redirect stdout to file. To redirect stderr to file, you can use '2>'
Try:
dvdauthor -x dvdauthor.xml 2> output.txt
You might find the BASH programming introduction useful for more info on redirecting output: http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html

How to capture stderr on Windows/DOS?

I want to capture the errors from a script into a file instead of to the screen.
In *nix, this is done with stderr redirection, usually
echo "Error" 2> errorfile.log
How do I do it in a CMD script under Windows?
For example:
PSKILL NOTEPAD >output.txt 2>&1
This will direct stdout and stderr to a file name output.txt.
See Underused features of Windows batch files for more details.
That should work in Win32, too.
If you have already redirected stdout, and want stderr redirected to the same file, you must use the 2>& special form, rather than just specifying the same file twice. Otherwise you'll get a "file busy" error.

Redirecting the darknet program's result to log file

I'm trying to redirect the results of darknet(yolo) program to my log file.
But there are some troubles in redirecting the result.
I tried ./darknet detect cfg/yolo.cfg yolo.weights image.jpg > log.txt, but it doesn't work.
And also other redirecting methods are not working.
I think the results of darknet program is not printed to stdout but printed to somewhere.( I don't know where it is.)
So, I have no idea to solve this problem.
Please help me...
How do I get this results in forms of file?
This appends all the standard output into a file. Remove 2>&1 if you don't want to log standard errors.
./darknet detect cfg/yolo.cfg yolo.weights image.jpg 2>&1 | tee -a log.txt
Detail info here.

Resources