2

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 ");
        }
    }

1 Answer 1

3

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();
Sign up to request clarification or add additional context in comments.

4 Comments

can you tell me how to convert that C# code to an exe file because I don't have any idea of .Net framework
@ManojSingh : if you have visual studio IDE then build the project so that it creates the .exe file in the respective project folder.
Sudhakar I need one more help from you -- I want to some argument to that exe file can you help me how to do this
Thanks :) . Its wroking

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.