This question already has answers here:
How to read console ouput
(2 answers)
Closed 8 years ago.
My grails app has an external java library which I developed. I want my grails app to be able to display my java library system.out statements (console output). How do I go about doing that?
I would rather not have to write it out to a file then read it in grails. There must be a better way of doing this.
**I want grails to display these to a text box as the happen(In a browser while its running(so the user can see))
Afer trying several of my own ways I have to settle for this way which I will post here. Thanks #Shaunak for your help and understanding.
**How I solved it.
In my java library I created a global class which all the System.outs will be wrote to
writeSouts(String sout){
//store here in a global string and keep appending to it as needs be
}
Then in grails constantly call the java library method. and using Ajax write it out to the browser window.
Hope this helps anyone in the future who encounters the same problem.
Also it is not for testing but an integral part of my web app so that the user of the web app can was the java library is doing in the background.
Without much details on how exactly you are invoking the Java Library, I will assume here that it is just some code that writes to console, and you want to invoke and read it from inside Grails controller and send it back to HTML. Here's what I would suggest. Instead of including the Java Code as a library, create a command line utility out of it.
So your java program will be invoked for testing like so,
java MyLib -arg1 -arg2
This will should out put something like this on the command line:
> This is my nice output
Now to to invoke and read this from grails, you can use Groovy's External Process Management
and do something like this to invoke and read the output:
def process = "java MyLib -arg1 -arg2".execute()
def response = "Found text ${process.text}"
Your response var should now have value
Found Text This is my nice output
You can now use this to do what ever in a grails controller, like send it back to HTML..
Related
This question already has answers here:
Execute Jar file from C sharp code and get return value
(2 answers)
Closed 7 years ago.
I have a c# application and I have a .jar file that I have created. I want to call from c# application, my jar file, I want to call a method in the jar file. I try to use JNI but I can't call jar file.
There is a mode to do this?
Your main problem is the lanuage incomaptabilities
As far as i understand there is no direct way that Java (jar) and c# assembles can talk to each other.
Question is what does the jar file do ? and can the same be done using c#
If not then you are going to have to create a java application using somethign like Netbeans to act as a kind of middle man
Then when the c# application does a function call the call gets serialised into a file
The java app should then look for the file (in a thread or something) pulling the data and writing the response data to the file
While asp.net looks for changes in the file and pulls the data back from the file once java has written
There are other options such as web service and TCP IP socket server to communicate
But Long story short there is no clear cut way as far as i am aware of that there is not clear cut way of making java and .net talk to each other .
A quick google search did bring up http://www.ikvm.net/userguide/tutorial.html[^] which seems to be promising.
Hope this helps
Our java program is suppose to call a program created by our vendor in C#. We are given two files
1.An exe file
2.An xml file...which its contents go something like this
<doc>
<assembly><name>someProgram</name></assembly>
<members>
<member name="P:SomeConnector.callSomeOtherProgram()">
<summary>a method to connect to some program</summary>
<remarks></remarks>
</member>
</members>
</doc>
We're clueless on how to so this. Anyone got ideas?
for running comman line in java use:
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("MyOtherProg.exe progParameter1 progParameter2");
judging by your comment and question i think you have a class library, and the right way to approach this would be to just create your own C# program that calls the different method on that class library using the given xml as a program args or other way
Edit
your comment:
unning the exe manually (double click) shows up a wizard with an input
text field and some buttons which does different tasks. the idea is
for our java program to automatically run it and provide the fields
and execute which buttons we would like to trigger to do the function
we want. the java program just automates whatever is done manually
answer:
ok, now we're coking with fire :)
so, at this point i would go to the vendor and ask if i can get a class library instead of the current ui, as you want it running automatically, without Human intervention. while on it i would check if you got other .dll files with the program. if so investigate them using VS.
one last thing, if all is turn bad and you have to do clicks, it's not lost yet, but at this point you have a lot of work, and i can't help you from here, but i'll send you to a link to start what you need and you'll explore from there:
clicking robot
youtube video on the subject
I want to access user's scanner using PHP script. I know this can be done by using PHP script on Linux based machine.
I want to put this script on the server and wanted to run it via Java Applet I don't know Java much also I am not sure if this task can be done by this way.
Please suggest if this is correct way and How to proceed on it.
Thanks for your time!
Can the scanner PHP code be operated purely via parameters in the URL? If so, then a Java applet could connect to those URLs passing parameters as necessary, and if the PHP script returns information in the HTML output stream (as if it were returning a web page), then the applet can parse the page it 'downloads' from that URL to get the information out. Not elegant, but do-able.
Is it possible to call/run a python script file from Java code on the Android platform using SL4A? Basically I have a full blown Java Android app and I have several Python scripts that scrape some information from various web pages. I would like to be able to call these python scripts with the web page and get the results back. Is this possible? If so, can anyone point me in the direction of an example or two?
Thank you,
Harry
run an SL4A script from my application?
http://code.google.com/p/android-scripting/wiki/FAQ#Can_I_run_an_SL4A_script_from_my_application?
Here you go, a solution on how to make Android applications using SL4A and Python. I have developed a functional Python application following this tutorial so I can vouch for it. I assume you can add the Python code and do your data exchange with JSON.
I personally have never tried to mix these two together, though I will probably try after seeing your post.
Also, if you have any problems/questions, related to starting that example, post them here, I might help.
I am newbie in wkhtmltopdf. I am wondering how to use wkhtmltopdf with my Dynamic Web Project in Eclipse? How to integrate wkhtmltopdf with my Java dynamic web application?
Is there any tutorials available for beginners of wkhtmltopdf ?
(Basically, I would like to use wkhtmltopdf in my web application so that when user click a save button , the current page will be saved to PDF file).
First, a technical note: Because you want to use wkhtmltopdf in a web project, if and when you deploy to a Linux server machine that you access via ssh (i.e. over the network), you will need to either use the patched Qt version, or run an X server, e.g. the dummy X server xvfb. (I don't know what happens if you deploy to a server running an operating system other than Linux.)
Second, it should be really quite simple to use wkhtmltopdf from any language in a web project.
If you just want to save the server-generated version of the current page, i.e. without any changes which might have been made like the user filling on forms, or Javascript adding new DOM elements, you just need to have an extra optional argument like ?generate=pdf on the end of your URL, which will cause that page to be generated as a PDF, and then the PDF button will link to that URL. This may be a lot of work to add to each page manually if you are just using simple JSP or something, but depending on which web framework you are using, the web framework may offer some help to implement the same action on every page, if you need to implement that.
To implement this approach, you would probably want to capture the response by wrapping the response object and overridding its getWriter() and getOutputStream() methods.
Another approach is to have a button "submit and generate PDF" which will generate the next page as a PDF. This might make more sense if you have a form the user needs to fill in - I don't know. It's a design decision really.
A third approach is to use Javascript to upload the current state of the page back to the server, and process that using wkhtmltopdf. This will work on any page. (This can even be used on any site, not just yours, if you make it a bookmarklet. Just an idea that occurred to me - it may not be a good idea.)
A fourth approach is, because wkhtmltopdf can fetch URLs, to pass the URL of your page instead of the contents of the page (which will only work if the request was a HTTP GET, or if it's equivalent to a HTTP GET on the same URL). This has some small amount of overhead over capturing your own response output, but it will probably be negligible. You will also very likely need to copy the cookie(s) into a cookie jar with this approach, since presumably your user might be logged in or have an implicit session.
So as you can see there are quite a lot of choices!
Now, the question remains: when your server has the necessary HTML, from any of the above approaches, how to feed it into wkhtmltopdf? This is pretty simple. You will need to spawn an external process using either Runtime.getRuntime().exec(), or the newer API called ProcessBuilder - see http://www.java-tips.org/java-se-tips/java.util/from-runtime.exec-to-processbuilder.html for a comparison. If you are smart about it you should be able to do this without needing to create any temporary files.
One of the wkhtmltopdf websites is currently down, but the main README is available here, which explains the command line arguments.
This is merely an outline answer which gives some pointers. If you need more details, let us know what specifically you need to know.
Additional info:
If you do end up trying to call wkhtmltopdf in an external process from java (or for that matter, any language), please note that the "normal" output that you see when using wkhtmltopdf from the command line (i.e. what you would expect to see in STDOUT) is not not in STDOUT but in STDERR. I raised this issue in the project page
http://code.google.com/p/wkhtmltopdf/issues/detail?id=825
and was replied that this is by design because wkhtmltopdf supports giving the actual pdf output in STDOUT. Please see the link for more details and java code.
java-wkhtmltopdf-wrapper provides an easy API for using wkhtmltopdf in Java.
It also works out-of-the-box on a headless server with xvfb.
E.g., on a Ubuntu or Debian server:
aptitude install wkhtmltopdf xvfb
Then in Java:
Pdf pdf = new Pdf();
pdf.addPage("http://www.google.com", PageType.url);
pdf.saveAs("output.pdf");
See the examples on their Github page for more options.