Reputation: 469
I have a java class and a c# class. I want to run that C# class from my java class.
However I don't want to pass anything from java code to c# and also don't want anything in return from C# code, I just want to run that C# code.
I want to do something like shown in below classes
Java Class:
public void static main(String[] args){
System.out.println("Running Java code ");
// here need to call C# class
}
}
I want this code to be executed from above java program
using System;
class Program {
Console.WriteLine("Running C# code ");
}
}
Upvotes: 2
Views: 718
Reputation: 26199
You can run the C# program exe
file from java code.
first compile the C#.NET program to get the Program.exe
file then run the same Program.exe
from java code as below:
public static void main(String[] args) throws IOException {
// TODO code application logic here
Process process;
process = new ProcessBuilder("C:\\ProjectsPath\\Program.exe").start();
}
Edit:
You can send the parameters to the exe file to be invoked by passing the arguments to the ProcessBuilder constructor as below:
Note : here im passing two argumenbts to Program.exe file Name and ID :
process = new ProcessBuilder("C:\\ProjectsPath\\Program.exe" , "Sudhakar","ID501").start();
Upvotes: 3