Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've been working on making a small application which uses both java and python. The GUI uses java and I would like to use a button to call a python script which will return a string to the java application. Problem is I have no idea how to return a string from python as strings are printed to to the error stream if returned in sys.exit().
Posted
Updated 9-Dec-14 1:11am
v2

1 solution

Use the Process class[^] which allows you to capture the output stream of the external process.
 
Share this answer
 
Comments
shahab96 9-Dec-14 7:12am    
Yes but that is what receives the string from the python script. What I am confused about is how to actually return the string from the script, as in Python you can't use a return statement outside a function and the way a script is handled is by using the lines

if __name__ == __main__:
<insert code="" here="">

and the return statement can't be used there.
Richard MacCutchan 9-Dec-14 7:20am    
You don't need to 'return' anything, just print the string to the normal output stream.
shahab96 9-Dec-14 7:22am    
Oh alright, thanks a lot!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900