0

This is not about creating a batch file or executing a batch file from java but creating a binary from them.

I am not very sure about Linux shell scripts but is know that for Windows Batch scripts there are some programs like Batch to Exe Converter. But i want to do it programmatically.

Suppose I read the contents of a batch file from a file :

public static String loadFile(String filepath) {
    List<String> lines = Collections.emptyList();
    try
    {
       lines =
       Files.readAllLines(Paths.get(filepath), StandardCharsets.UTF_8);
    }
    catch (IOException e)
    {
       e.printStackTrace();
    }
    String s = "";
    for(String line:lines){
        s += line + "\n"
    }
    return s;
}

Now i want to convert it to an exe.

Purpose

My main purpose is to create small executables from those scripts for some small automations which will be used instead of the scripts themselves.

For example:-

I have a setup.bat file.

I have my program to automatically generate the batch every time I make any changes(add files) now i also want to have executables along with the scripts.

I also a curious whether a similar thing is possible for Linux shell scripts(creating executables).

Moreover i this is not possible through Java directly can we some how do it using JNI?

Jaysmito Mukherjee
  • 1,467
  • 2
  • 10
  • 29
  • 1
    certutil can be utilised in your batch file to create executables. See the answer [here](https://stackoverflow.com/a/30837689/12343998) for an example of how – T3RR0R Jun 10 '21 at 02:53
  • The link bellow could be what you are looking for. You can call the command in your Java program to generate the exe file. https://superuser.com/questions/868340/how-can-i-convert-a-windows-batch-script-to-a-exe – Harry Coder Jun 10 '21 at 03:56
  • @HarryCoder the link 1st is using a gui interface so idk how to call from code(more over iexpress just is a wrapper) second one is using the batch to exe converter itself that is too not use full as i want to do it from my program it self and if it is not possible in java i am ready to go C++ through JNI – Jaysmito Mukherjee Jun 10 '21 at 04:53

0 Answers0