Redirect messages


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Redirect messages
# 1  
Old 01-03-2007
Redirect messages

I have this script which invoke a java program and in the program I have several System.out.println
statement to write messages to standard output, I wanna to redirect these to a log file so I did

java blah blah blah > log.txt 2>&1

but I can't see any of those messages, can anybody help? Thanks!
# 2  
Old 01-03-2007
It should work

Code:
[/tmp]$ cat test.java
import java.io.*;

public class test
{
    public static void main (String[] args)
    {
        System.out.println ("Hello World\n");
    }

}
[/tmp]$ java test
Hello World

[/tmp]$ java test > /tmp/java.log
[/tmp]$ cat /tmp/java.log 
Hello World

[/tmp]$

Try this

Code:
java blah blah blah > log.txt 2>log.txt

# 3  
Old 01-03-2007
If you are looking to do quite a bit of output within your java code to standard output I would recommend using a package such as log4j -

http://logging.apache.org/log4j/docs/index.html

Has lots of nice customizable options for creating log files depending on how creative you want to be Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ftp redirect

Hi i want to redirect a list of ftp file to an exsisting file by mls x.txt mylocalfile.txt result of this command corrupt my data on mylocalfile.txt , please help me (2 Replies)
Discussion started by: rezasadeghi
2 Replies

2. Shell Programming and Scripting

How to redirect the messages from the script to console in Linux?

msg.sh #!/bin/bash if then echo "starting service" else echo " service not started" echo " Please check the start.sh file or manuly start the service" fi if i login with root credentials @12.36.34.123 with passwd username:root passwd:abc once i login into linux pc... (6 Replies)
Discussion started by: saku
6 Replies

3. Web Development

.htaccess redirect with #

I have the following directive in my .htaccess: #RewriteRule ^mozrank/?$ "http://www.seobook.com/#a_aid=dh" The problem is that the redirect is going to http://www.seobook.com/%23a_aid=dh How to preserve the # when redirecting? (2 Replies)
Discussion started by: rlopes
2 Replies

4. Shell Programming and Scripting

Redirect Output

Hi, I would like to list files: ls *.hdf But I would like a copy of the output directed to the screen, but also APPENDED to a text file: test.txt I have tried: ls *.hdf | tee test.txt However, that will just write over everything already existing in test.txt. How can I append the... (1 Reply)
Discussion started by: msb65
1 Replies

5. SCO

Redirect archive0?

Hello UNIX-community, We have an older SCO UNIX-system running PCS3 (an industrial platform) and since a few weeks we are experiencing problems with our archiving software. For about ten years, the system archives data to Magneto-Optical discs (MO-discs) and thus far it has worked fine.... (0 Replies)
Discussion started by: V4Friend
0 Replies

6. HP-UX

How to Redirect the error messages from Syslog file to our own Application Log File

Hello, I am New to Unix. I am Using HP-UX 9000 Series for my Application. I am Currently Facing an Issue that the error messages are being written in the syslog file instead of the Application Log File. The Codes for that Syslog.h is written in Pro*C. I want to know how to Redirect these... (3 Replies)
Discussion started by: balasubramaniam
3 Replies

7. Shell Programming and Scripting

Redirect output

Hi all, I have a script which call a java program, the logging (to log file) in the program is done using log4j. However, as a safety measure, i still choose to direct standard error to another log file as follow /usr/bin/java -classpath ${classpath} -Xmx128m TestingProgram 2>>... (1 Reply)
Discussion started by: mpang_
1 Replies

8. Shell Programming and Scripting

redirect exception messages from program

Hi, I have a script which invoke a java program and I would like to know whether it is possible to log the exception thrown by the program to a log file in the script? Thanks! (1 Reply)
Discussion started by: mpang_
1 Replies

9. UNIX for Dummies Questions & Answers

Need to redirect the messages

Hi, Some of the process execuating on our server time to time. Time of exeuation is not know in advance. That process is producing some of the messages on the screen. I want to redirect all the messages in one file as well as want all the message on the screen also. How i can do that ? (2 Replies)
Discussion started by: gaur_amar
2 Replies

10. IP Networking

Redirect

I'm sittig behind a firewall that doesn't allow ftp. I have a conection to a UNIX system, connecting throug SSH. Is it possible to redirect the ftp through the UNIX to my computer? (1 Reply)
Discussion started by: <Therapy>
1 Replies
Login or Register to Ask a Question