0

I want to send a int value from a Java GUI to a C program. Later on in the code the C program will return a value back using native commands. Apologies as their's no code as their's nothing to show at the moment. Doing some research on how to do this still.

So my problem is how can i send results from java to C. Googling only seems to show socket tutorials and solutions. Mine isn't a network based program so any network communications isn't needed.

From what I can see with native commands, it only works sending C code to Java. Not the other way around.

the value has to come from Java, not C. Reason being is I'm implementing a Java GUI interface that creates a link-list in C.

lecardo
  • 1,208
  • 4
  • 15
  • 37
  • 2
    You are looking for IPC, it depends on the OS. – Iharob Al Asimi Jan 23 '15 at 18:54
  • The question is how do you want to *send* it. If you mean to run a subprocess, and pass it on the command line or to stdin, should be no problem. If however you want to communicate to another process on your own machine, then IPC is the way to go (or sockets if running across a network) – user590028 Jan 23 '15 at 18:59
  • If your C code is a library (not a program in the strict sense), JNI would be an obvious choice. – Drux Jan 23 '15 at 19:01
  • Named pipes could be a solution. See here http://stackoverflow.com/questions/18653236/ipc-between-java-and-c – chris Jan 23 '15 at 19:14
  • Languages are totally irrelevant. Your OS (Linux, Windows, etc.) has facilities for one process to share data with another--there are different ones. Sockets are good, because they can be used on the same machine as well as over a network. Pipes are good. There's also more obvious things like writing to a file. – Lee Daniel Crocker Jan 23 '15 at 20:33

1 Answers1

0

What you are looking for is IPC. InterProcess Communication. There are different methods for IPC. One platform independent way is to use sockets.

Let your c program listens for connections from localhost to a particular port. Your java program can connect to this port and send data over this network sockets. Then your C program may process it and send the result back to the java program.

ninja
  • 809
  • 5
  • 9