0

I want to execute a .exe file i made from C code :

#include <stdio.h>
#include <stdlib.h>

void helloFromC(){
    printf("Hello from C!");
}

int main(){
 helloFromC();
 return 0;
}

Currently this is what i am trying but it gives me Error: Could not find or load main class Test (which is the class i am currently using in Java):

import java.io.IOException;

public class Test {
    public static void main(String[] args) {
        try {
            String filename = "D:\\eclipse\\workspace\\Testing\\TestFile.exe";
            Runtime rTime = Runtime.getRuntime();
            Process p = rTime.exec(filename);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
Ann
  • 377
  • 5
  • 16

1 Answers1

1

Your questoin already been answered in Stackoverflow.

Could not find or load main class

You can execute executable using ProcessBuilder class in Java.

Without Parameters:

Process process = new ProcessBuilder("C:\\ExecutablePath\\TestExe.exe").start();

With Parameters:

Pass your arguments in constructor itself.

Process process = new ProcessBuilder("C:\\ExecutablePath\\TestExe.exe","param1","param2").start();
Community
  • 1
  • 1
Amit Tamrakar
  • 512
  • 3
  • 13