Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] appending/inserting tSystem Output to a (log) file

I'm trying to figure out how to append the value of ((String)globalMap.get("tSystem_1_OUTPUT")) to an output file. I've got my standard and error outputs both going "to global variable."
I originally thought maybe I could use a tFixedFlowInput, but the other issue to contend with is that my standard output has the potential to be large... like, according to a text editor i used to look at one set of output (see 3rd pic): Byte count = 95,923
Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Ok, I found a way. But if anyone knows of an easier way to do this, I am all ears!
If Link
!((String)globalMap.get("tSystem_1_OUTPUT")).equals(null)
||
!(((String)globalMap.get("tSystem_1_ERROROUTPUT")) == null)
||
!(((String)globalMap.get("tSystem_1_ERROR_MESSAGE")) == null)

tJavaFlex_1
*Advanced Settings
***Import
import java.io.*;

*Basic Settings
***Start code
Writer output = null;
File file = new File(context.BatchLogFile);
output = new BufferedWriter(new FileWriter(file, true));

***Main code
output.write("\n");
output.write("\n");
output.write("********************************************************************************************************");
output.write("\n");
output.write("\n");
output.write("Start Date/Time= " + TalendDate.getCurrentDate());
output.write("\n");
output.write("\n");
if ( !((String)globalMap.get("tSystem_1_OUTPUT")).equals(null) ) {
output.write("------------------------------------Standard Output-------------------------------------");
output.write("\n");
output.write(((String)globalMap.get("tSystem_1_OUTPUT")));
output.write("\n");
}
if ( !(((String)globalMap.get("tSystem_1_ERROROUTPUT")) == null) ) {
output.write("--------------------------------------Error Output--------------------------------------");
output.write("\n");
output.write(((String)globalMap.get("tSystem_1_ERROROUTPUT")));
output.write("\n");
}
if ( !(((String)globalMap.get("tSystem_1_ERROR_MESSAGE")) == null) ) {
output.write("--------------------------------------Error Message-------------------------------------");
output.write("\n");
output.write(((String)globalMap.get("tSystem_1_ERROR_MESSAGE")));
output.write("\n");
}
output.write("\n");
output.write("\n");
output.write("End Date/Time= " + TalendDate.getCurrentDate());
output.write("\n");
output.write("\n");
output.write("********************************************************************************************************");
output.write("\n");
output.write("\n");

***End code
output.close();

Related Information
http://www.roseindia.net/java/beginners/WriteTextFileExample.shtml
http://www.roseindia.net/java/example/java/io/java-append-to-file.shtml
http://java.sun.com/j2se/1.4.2/docs/api/java/io/Writer.html
http://java.sun.com/j2se/1.4.2/docs/api/java/io/BufferedWriter.html
http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileWriter.html
FileWriter(String fileName, boolean append)
Constructs a FileWriter object given a file name with a boolean indicating whether or not to append the data written.
boolean append values: true, false

View solution in original post

1 Reply
Anonymous
Not applicable
Author

Ok, I found a way. But if anyone knows of an easier way to do this, I am all ears!
If Link
!((String)globalMap.get("tSystem_1_OUTPUT")).equals(null)
||
!(((String)globalMap.get("tSystem_1_ERROROUTPUT")) == null)
||
!(((String)globalMap.get("tSystem_1_ERROR_MESSAGE")) == null)

tJavaFlex_1
*Advanced Settings
***Import
import java.io.*;

*Basic Settings
***Start code
Writer output = null;
File file = new File(context.BatchLogFile);
output = new BufferedWriter(new FileWriter(file, true));

***Main code
output.write("\n");
output.write("\n");
output.write("********************************************************************************************************");
output.write("\n");
output.write("\n");
output.write("Start Date/Time= " + TalendDate.getCurrentDate());
output.write("\n");
output.write("\n");
if ( !((String)globalMap.get("tSystem_1_OUTPUT")).equals(null) ) {
output.write("------------------------------------Standard Output-------------------------------------");
output.write("\n");
output.write(((String)globalMap.get("tSystem_1_OUTPUT")));
output.write("\n");
}
if ( !(((String)globalMap.get("tSystem_1_ERROROUTPUT")) == null) ) {
output.write("--------------------------------------Error Output--------------------------------------");
output.write("\n");
output.write(((String)globalMap.get("tSystem_1_ERROROUTPUT")));
output.write("\n");
}
if ( !(((String)globalMap.get("tSystem_1_ERROR_MESSAGE")) == null) ) {
output.write("--------------------------------------Error Message-------------------------------------");
output.write("\n");
output.write(((String)globalMap.get("tSystem_1_ERROR_MESSAGE")));
output.write("\n");
}
output.write("\n");
output.write("\n");
output.write("End Date/Time= " + TalendDate.getCurrentDate());
output.write("\n");
output.write("\n");
output.write("********************************************************************************************************");
output.write("\n");
output.write("\n");

***End code
output.close();

Related Information
http://www.roseindia.net/java/beginners/WriteTextFileExample.shtml
http://www.roseindia.net/java/example/java/io/java-append-to-file.shtml
http://java.sun.com/j2se/1.4.2/docs/api/java/io/Writer.html
http://java.sun.com/j2se/1.4.2/docs/api/java/io/BufferedWriter.html
http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileWriter.html
FileWriter(String fileName, boolean append)
Constructs a FileWriter object given a file name with a boolean indicating whether or not to append the data written.
boolean append values: true, false