2

I search to make a binding beteewn a Java Process and a C# Process. My last idea is : compile a java process into a .exe, in order to directly launch it from the c# process without pass by java.exe

Is it possible? if yes, could you help me a little please?

Have a good day

edit : this topic is not an answer to my question, because if i wanted use process, it's because i want that c# process run java process

Community
  • 1
  • 1
  • You cannot compile a Java source file into an `exe`; what you can do is programatically invoke a JVM via a C/C++ API; maybe a wrapper exists in C#? – fge Jun 03 '13 at 13:18
  • If they "only" have to communicate, you can use the local network stack (sockets). Or start the process and use std.in/out streams. – Fildor Jun 03 '13 at 13:23

2 Answers2

1

You could use the Process framework to start your Java program (compiled as a runnable JAR) and pass in command-line parameters which allows the Java program to "know" how to behave, assuming the communication isn't incredibly complex between the two programs.

Process javaProcess = new Process();
javaProcess.StartInfo.FileName = "C:\\Path\\To\\yourJavaProgram.jar";
javaProcess.StartInfo.Arguments = "EXECUTE_FROM_C_SHARP"; //or whatever
javaProcess.Start();

//Wait for the Java program to finish doing its thing before resuming
javaProcess.WaitForExit();
asteri
  • 11,402
  • 13
  • 60
  • 84
0

Utilize the stdin and stout streams. Start a new process in C# calling the java program. The process's stdin will route to the stdin of the java process (System.in by default). Same for stdout.

Russell Uhl
  • 4,181
  • 2
  • 18
  • 28