Redirecting the shell output to a file
Try redirecting stderr
also:
/usr/IBM/WebSphere/AppServer/java/bin/java -verbose:class -cp "XXXXX" com.ibm.XXXX >>/home/user/log.log 2>&1
Your Java code might be writing on stderr
that your command isn't redirecting.
Redirect stdout to a string in Java
Yes - you can use a ByteArrayOutputStream
:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
System.setOut(new PrintStream(baos));
Then you can get the string with baos.toString()
.
To specify encoding (and not rely on the one defined by the platform), use the PrintStream(stream, autoFlush, encoding)
constructor, and baos.toString(encoding)
If you want to revert back to the original stream, use:
System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
How do I redirect to a html page and pass variables to that page in Java?
In a Java Servlet, you'll want to write:
response.sendRedirect("index.html?var1=a&var2=b...");
Oh right, I should note that you'll want to do this in the processor method like doGet() or doPost()...
Redirect java output with bash script (liquibase)
The problem is in:
output=$(liquibase --"lots of parameters here") > /dev/null 2> /dev/null
The STDOUT
and STDERR
redirections become useless when you say so. You'd continue to see the STDERR
on the terminal.
In order to redirect both the STDOUT
and STDERR
of the command into the variable, say:
output=$(liquibase --"lots of parameters here" 2>&1)
In order to redirect the STDOUT
into the variable and discard the error completely, say:
output=$(liquibase --"lots of parameters here" 2>/dev/null)
Related Topics
Difference Between Using Java.Library.Path and Ld_Library_Path
How to Get the Ip of the Computer on Linux Through Java
Installer/Packager for a Java Application for Ubuntu and Suse
Wait Until Tomcat Finishes Starting Up
How to Use Linux Shared Libraries in Java
Commons Vfs and Java.Net.Url - Adding Support for "Sftp://" Protocol
Local_Policy.Jar and Us_Export_Policy.Jar Different with Unlimited Strength VS Default
How to Open a Unc Path from Linux in Java
Kiosk Mode for Linux Java Swing Application
How to Set Ld_Library_Path for Java Process
Equivalent of Data Protection API on Linux
Hadoop Mapper Is Failing Because of "Container Killed by the Applicationmaster"
Why Must Wait() Always Be in Synchronized Block
Java Switch Statement: Constant Expression Required, But It Is Constant
How to Create a Linux Cluster for Running Physics Simulations in Java