Redirect Java -Version to File or Variable

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



Leave a reply



Submit