How do I check what version of java im using in c++ - java

I have a testing script that checks what version of java the user is using and then executes some commands. But we are trying to convert all of our testing into cxxtests. I would like to know how to convert my version checking script into c++ code. I know I could just use the system() command but I would like that to be a last resort. Any help or leads would be appreciated.
Thanks,
Josh

You have to use the system() command, or a C++ library that will use the system() command. This task is much better done in a shell script than C++ code. If necessary, the shell script can call C++ code to do notifications, or whatever it is that's causing the reliance on C++.

Related

Use Java program from Python

I'm using Python to launch a java program and to extract its results using os.system
os.system("java myprogram")
The problem is this launch the program on console and I have to type command inside the program to extract the result.
Do somebody know how to give command to the java program from Python ?
Thank you,
Easy way to invoke java program or any other script is using subprocess in python.
The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. This module intends to replace several older modules and functions
Read more about subprocess
Example:
subprocess.Popen - Following will invoke your script in background.
subprocess.Popen(["java", "ProgramPath/filename.java", "arg1", "arg2", "arg3"])
subprocess.call - And this will wait for the command to complete.
subprocess.call(["java", "ProgramPath/filename.java", "arg1", "arg2", "arg3"])
subprocess.check_output - will return you the output
output = subprocess.check_output(["java", "ProgramPath/filename.java", "arg1"])
http://www.jython.org/jythonbook/en/1.0/JythonAndJavaIntegration.html
This chapter will focus on integrating Java and Python, but it will explore several different angles on the topic. You will learn several techniques to make use Jython code within your Java applications. Perhaps you’d like to simplify your code a bit; this chapter will show you how to write certain portions of your code in Jython and others in Java so that you can make code as simple as possible.

How to package a python script with my java program?

So, I'm writing a program(mostly for practice, kind of for future convenience) that will show a java front-end when run, and depending on the input, will use a python script to crawl and interpret a webpage, then send the interpreted data back to java to format for the front end. I'm sure I can get this running on my own computer, but when I want to distribute my program for my friends to use, how can I ensure my java program, mainProgram.jar can find my python code, script_x.py. Is there a way I can assure my python script will be supported. I've read that there are ways to include the necessary runtimes and such with your program when you build it, but would it still interact the same way with my java program if it was bundled with it's dependencies? I can provide some sample code soon, but it's still a work in progress, as I don't have the python script finished yet.
here is a link https://bytes.com/topic/python/insights/949995-three-ways-run-python-programs-java
use Jython (compiles to java byte code) https://en.wikipedia.org/wiki/Jython
distributing Jython applications: https://wiki.python.org/jython/JythonFaq/DistributingJythonScripts

Execute java class from php

I want to execute some java class for doing some bacground work,(have no any ui related task).like file read, write in a specific location. My main server side is done by php. I want to call these java program from php file. I study about Java/PHP Bridge. But i could not understand what i have to use like jse program(not suitable in server),jsp application (have no gui), or by a ejb. Please tell me what will be the best option to do that?
You can execute a program in a couple of ways:
exec()
system()
passthru()
shell_exec() or the shell execution operator (the backticks, ``)
Which one to use depends on what you want. You should study the above links and figure out which one to use.
Use the exec() function:
exec("java Main.class");

how can we run python script(which uses nltk and scrapy) from java

I have written python scripts that use scrapy,nltk and simplejson in my project but i need to run them from java as my mentor wants to deploy them on a server and i have very less time to do this.I took a glance at runtime.exec() in java and jython, needless to say that running system commands from java doesn't look simple either.
So I would like to know if running the python scripts from java as system command -'python example.py ' using runtime.exec() or alternatively using jython would be more simpler and actually feasible or whether there is a simpler workaround .It would also be great to know if anyone had run python code that uses nltk from java using Jython and whether they encountered any problems.Please help me as I have to do this as asap.Any thoughts and suggestions regarding this are welcome.
Thanking in advance!!
The Jepp project lets you call python scripts from Java. It provides an easy mechanism to pass variables into a script and extract values back. I've used on a few projects with good success

Calling Java from Python

I have a Java app that takes a long time to be initialized (so I can't use a command-line like interface) and I need to pass text and receive the output of a Java method from Python. Is it possible to load the Java application, have it open all the time the Python script runs and use a method from that app?
I don't think the use of Python helps all that much over a command line (at least not a *nix command line), but the basic idea is to communicate over a socket or some similar mechanism. That means that the Java application will have to be wrapped in some code which opens a socket and waits for the python script to contact it. If you are most comfortable with python, you could look to implement that wrapper in Jython.
I've used JPype for something similar and it worked great.
JPype is an effort to allow python programs full access to java class libraries. This is achieved not through re-implementing Python, as Jython/JPython has done, but rather through interfacing at the native level in both Virtual Machines.
If the java app is running you should also consider xml-rpc as it also works well.
Py4J is a way to call Java from a python script. Here is the project website: http://py4j.sourceforge.net/

Categories

Resources