473,382 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

python under java2

For some reason i need to start a python script from inside a java code. The
main part of the code is something like this

try{
Runtime rt = Runtime.getRuntime();
System.out.println("start");
Process proc = Runtime.getRuntime().exec("python myscript.py");
proc.waitFor();
System.out.println("end");
} catch (Exception e){
e.printStackTrace();
}

and so worked for months....but since some days ago the same instruction
does not work but execute without any exception, that is print either
"start" and "end"; the strangest thing happen when I call just

Process proc = Runtime.getRuntime().exec("python myscript.py");

the execution looks like stalled and does not comes to an end printing just
the "start".

Some suggestion?
My machine is a Linux Mandrake64 10.1


Jul 18 '05 #1
1 1522
motokoit wrote:
For some reason i need to start a python script from inside a java code. The
main part of the code is something like this

try{
Runtime rt = Runtime.getRuntime();
System.out.println("start");
Process proc = Runtime.getRuntime().exec("python myscript.py");
proc.waitFor();
System.out.println("end");
} catch (Exception e){
e.printStackTrace();
}

and so worked for months....but since some days ago the same instruction
does not work but execute without any exception, that is print either
"start" and "end"; the strangest thing happen when I call just

Process proc = Runtime.getRuntime().exec("python myscript.py");

the execution looks like stalled and does not comes to an end printing just
the "start".

Some suggestion?
My machine is a Linux Mandrake64 10.1

I think this is probably really a java question. I suspect that your
python script is issuing too much output either on stdout or stderr,
and because you are not reading these streams, the process is blocking
because the output buffers are full. If this is the case, you need to
get your java program to read the streams (Process.getInputStream()
and Process.getErrorStream()), which is something you should be doing
anyway. In order to read both streams, you either need two threads, or
to use java.nio and select.

A short term fix might be to run theh python script by hand and see if
it throws out a long stack trace (this could block an unread error stream).

HTH
Steve
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Irmen de Jong | last post by:
QOTW: "Giving full access rights to a secretary or new programmer ought to insure an occasional random file deletion." -- Raymond Hettinger "I always use join, but that's probably because that...
0
by: Irmen de Jong | last post by:
QOTW: "Confronting the Martellibot is like flirting with an encyclopedia, I'd rather not do it myself, but I respect those who do, because it produces knowledge." -- Anton...
0
by: Irmen de Jong | last post by:
QOTW: "I'll claim without proof that how mixed-type comparisons work with Python classes is also beyond wizard prediction in all cases: the implementation of comparison in Python is crushingly...
0
by: Irmen de Jong | last post by:
QOTW: "To make the instructions even friendlier it would also help if 'but Whatever You Do DON'T UNZIP THE FREAKIN' THING - This Means YOU John Latter!' were in large, bold, and underlined type. ...
0
by: Irmen de Jong | last post by:
QOTW: "What can I do with Python that I can't do with C#? You can go home on time at the end of the day." -- Daniel Klein "Python lends itself to playing with it and to discussing the merits of...
3
by: Thomas Weholt | last post by:
Hi, Is it at all possible to use python to make apps on cellular/mobile phones, using something like Jython etc. ? Hm ... ?? Thomas
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.