This content has been marked as final.
Show 7 replies
-
1. Re: Getting java "System.out.println" content in a CF template
cf_dev2 Jul 3, 2007 10:40 AM (in response to Winter999)I can think of a few options. Truthfully, I think it would be easier in the long run if you rework the java method(s) to return the values you need so you can easily use them in ColdFusion. They can return a simple value like an int egeror a structure type object (ie. multiple values)
Another simple option is to run the clases using the command line java.exe program (using cfexecute). Then save the output to a file and parse it.
-
2. Re: Getting java "System.out.println" content in a CF template
Winter999 Jul 3, 2007 10:48 AM (in response to cf_dev2)Thanks for the tip, however the printlns are everywhere. I was hoping that I wouldn't have to modify the java code in case another app was calling them. The methods are called from within a html wrapper and the raw output dumped into a DIV.
I'll give the cfexecute a shot again; I had tried this a few hours ago with no luck. -
3. Re: Getting java "System.out.println" content in a CF template
cf_dev2 Jul 3, 2007 10:56 AM (in response to Winter999)You can also add a new method, if you're concerned about changing existing methods.
-
4. Re: Getting java "System.out.println" content in a CF template
Winter999 Jul 3, 2007 11:35 AM (in response to cf_dev2)Still banging my head against a wall. After doing some checking, I think I'm the only one using these java apps, but still the "println" is in hundreds of locations. Is there a way to redirect the output or feed it back to the calling CF template? I've tried CFOBJECT and CFEXECUTE and am getting nowhere. I've also tried using System.setOut(), but don't know what I'm doing.
Please keep in mind, that I'm fresh to java, so I could use code samples that I could cut/paste with little modification. Running these apps from the commandline gives me the proper output, I just can't get that same output back into my web page. If the printlns were everywhere, I could return the strings (maybe?). Lastly, I'm warry that if I write the strings out to file, that these apps are run asych so I'd have to design a filing scheme or risk overwrite.
Thanks for your patience with a frassled newbie. -
5. Re: Getting java "System.out.println" content in a CF template
Winter999 Jul 3, 2007 12:28 PM (in response to Winter999)Got it!
I finally figured out how to redirect the output stream and then return the var's .toString().
Java:
public static String main(String[] args)
throws Exception
{
ByteArrayOutputStream outstream = new ByteArrayOutputStream();
PrintStream ps = new PrintStream( outstream );
System.setOut( ps );
if ( args.length < 1 )
{
System.out.println("usage: java InetLoad inet_sales_spreadsheet");
return(outstream.toString());
}
inetLoad.run();
return(outstream.toString());
}
CF:
<cfoutput>
#UploadObject.main(params)#
</cfoutput>
Time for a beer. -
6. Re: Getting java "System.out.println" content in a CF template
Stressed_Simon Jul 3, 2007 2:01 PM (in response to Winter999)See the answer I gave you here I think you will find it helpful:-
http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=3&threadid=1281576&foru mid=1 -
7. Re: Getting java "System.out.println" content in a CF template
cf_dev2 Jul 3, 2007 4:59 PM (in response to Winter999)Glad you figured it out. I probably still lean towards returning values from the method(s) instead of using System.out.println ;-) .. but since you said there are 100's of output lines, redirecting the output sounds like a good choice for now.
> Time for a beer.
Have two. You earned it ;-)