The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how can i run java program from any where umen Shell Programming and Scripting 1 06-12-2006 10:36 PM
Invoke java program in script mpang_ Shell Programming and Scripting 0 03-27-2006 11:05 PM
Invoke java program in different processc d liux99 UNIX for Advanced & Expert Users 1 08-18-2005 01:47 AM
executing the su command from a java program. shailendrat UNIX for Dummies Questions & Answers 1 03-24-2005 12:27 PM
Java program calling a UNIX command QUartz Ite UNIX for Dummies Questions & Answers 2 11-15-2001 09:17 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-13-2001
lmnt22 lmnt22 is offline
Registered User
  
 

Join Date: Oct 2001
Location: The Netherlands
Posts: 4
Communication between a java and c++ program

Hi,

I have the following problem. I have 2 programs, a java program and a c++ program. These 2 programs have to communicate with each other in full duplex mode. I want to use pipes for this communication. So when the c++ program pust something on the stdout the java program must be able to read this and the other way around. Can, or is it wise to use pipes for doing this and if it isn't, what other options do I have?

thx in advance,

lmnt22
  #2 (permalink)  
Old 11-13-2001
Sven28 Sven28 is offline
Registered User
  
 

Join Date: Oct 2001
Location: Germany
Posts: 7
Try running the c program over jni (java native interface)
assuming you have the c++ program source code
over jni methods you can put the other language directly into your java program and define interfaces so there is no need to go over stdout etc

-hope this helps- :-)
  #3 (permalink)  
Old 11-13-2001
rwb1959's Avatar
rwb1959 rwb1959 is offline
Registered User
  
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
From your question, I assume you have 2
separate programs (1 java and 1 c++) and have
the source code for these programs. I also
assume that each of these programs reads stdin
for it's data and writes data to stdout.

I also assume that these programs have no
relationship to each other meaning that one
program does not start the other as a child.

If you want to use pipes, you may want to
consider FIFO devices (sometimes referred to
as a "named" pipe). You can create FIFO's
using the "mknode" command. If you want you
programs to utilize stdin and stdout, for example:

myjavaprog < /dev/myfifo1 > /dev/myfifo2 &
myc++prog < /dev/myfifo2 > /dev/myfifo1

then your code should first close all open
file descriptors and open /dev/myfifo1 and
/dev/myfifo2 for reading or writing as
appropriate. Also, you should open a file
for error output as well. Once you've done this,
the programs should work as if stdin and stdout
have been redirected. The main caveat here is that
you can expierence deadlock if your programs
block on reading or writing as reading and empty
pipe will wait forever and writing a full pipe
will block forever unless you set up your
connections as non-blocking. There are actually
a number of ways to deal with this but it does
require some forthought.

I hope this helps a bit.
  #4 (permalink)  
Old 11-13-2001
lmnt22 lmnt22 is offline
Registered User
  
 

Join Date: Oct 2001
Location: The Netherlands
Posts: 4
Thx guys,

I discussed both methods with my collegue and we didn't choose any of both methods. One of the issues is that both programs have to be portable to almost any system. We don't realy know if windows pipe handling is the same as unix pipe handling. It pipes isn't an option. (I only found this out after I wrote the topic)

Considering the small amount of time we have to complete the project we decided to implement some messeging system, which is indipendent of the method u use for in/output. For now we use 2 temp files which for each program (there are indeed 2 programs, a java program and a c program). But it might be possible to use pipes or sockets in the future. An advantage is that there doesn't have to be send much data between the 2 programs.(java is the gui and the c++ program handles the openGL drawing and heavy calculations).

So we use temporary files. However I would like to thank you for your fast response!

lmnt22
  #5 (permalink)  
Old 11-13-2001
rwb1959's Avatar
rwb1959 rwb1959 is offline
Registered User
  
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
Portability to Windoze is a very significant
addition to your orignally stated problem
however, you still have some options.
Here's an interesting article on Linux and Win2K
pipes...

http://www-106.ibm.com/developerwork...,l=805,p=pipes

...and from MS...

http://msdn.microsoft.com/library/de...pipes_2vqr.asp

...it may give you more ideas and options.

Personally, I would recommend sockets.
Enjoy
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:50 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0