Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Kura » Python script from Kura
Python script from Kura [message #1692288] Tue, 14 April 2015 19:06 Go to next message
Harsh Roy is currently offline Harsh RoyFriend
Messages: 2
Registered: April 2015
Junior Member
Hi,

This can be very basic question, I was experimenting with raspberry pi and kura. I created some applications in python.

Now is there any way i can "Start" "Stop" application from Kura. I know Kura is JAVA based. But still is there any way i can do that ?

Thanks.
Re: Python script from Kura [message #1692406 is a reply to message #1692288] Wed, 15 April 2015 13:36 Go to previous messageGo to next message
Davide De Cesaris is currently offline Davide De CesarisFriend
Messages: 30
Registered: January 2015
Member
Hi,

you can start a new process within your Java code with:

ProcessBuilder pb = new ProcessBuilder("/usr/bin/python", path_to_python_script, args);
Process p = pb.start();


Then, if you want to get the output of that script, you can simply write this:

BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));


and use that input buffer to read whatever you want.
Re: Python script from Kura [message #1692605 is a reply to message #1692406] Thu, 16 April 2015 19:25 Go to previous messageGo to next message
Harsh Roy is currently offline Harsh RoyFriend
Messages: 2
Registered: April 2015
Junior Member
This is accurate. Thanks for reply. Working on it.
Re: Python script from Kura [message #1705906 is a reply to message #1692605] Wed, 19 August 2015 23:11 Go to previous message
Amit Kumar Mondal is currently offline Amit Kumar MondalFriend
Messages: 108
Registered: March 2015
Location: Munich, Germany
Senior Member

I know this is an old post but just to give an update for other users in need, one can use Eclipse Kura's Inbuilt Feature of executing a Process. Eclipse Kura Core Bundle has classes to execute Process in a separate thread.

Eg.
                SafeProcess process = null;
		BufferedReader br = null;
		final String[] command = { CMD_PYTHON, CMD_PYTHON_ARG };

		try {
			process = ProcessUtil.exec(command);
			br = new BufferedReader(new InputStreamReader(process.getInputStream()));
			String line = null;

			while ((line = br.readLine()) != null) {
				if (line.contains("command not found")) {
					LOGGER.error("Resetting Command Not Found");
					throw new KuraException(KuraErrorCode.OPERATION_NOT_SUPPORTED);
				}
			}

			LOGGER.info("Executing process...Done");
		} catch (final Exception e) {
			LOGGER.error(Throwables.getStackTraceAsString(e));
		} finally {
			try {
				LOGGER.debug("Closing Buffered Reader and destroying Process", process);
				br.close();
				process.destroy();
			} catch (final IOException e) {
				LOGGER.error("Error closing read buffer", Throwables.getStackTraceAsString(e));
			}
		}


Amit Kumar Mondal
Email: admin@amitinside.com
Skype: arsenalnerk Blog: blog.amitinside.com
Previous Topic:Learning OSGi
Next Topic:Kura Emulator Error
Goto Forum:
  


Current Time: Wed Sep 25 15:14:33 GMT 2024

Powered by FUDForum. Page generated in 0.05069 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top