0

I am trying to create a tool using java where I want to embed and execute external third party exe and get the output from it in my tool that I am creating.

My constraint is that I cannot let the user get hold of this embedded exe on the system that I am running the tool on, so it must be dynamically deployed, executed and receive output from it and then deleted before the user exits the tool. My tool can be either a jar or an exe.

Is there a way to do this?

Henrik Aasted Sørensen
  • 6,966
  • 11
  • 51
  • 60
Priya
  • 1
  • 1
  • No, there is no way to do it, for two reasons: One, a Java application is an archive which any user can examine. Two, you will have to write your executable to a separate file in order to execute it, and the user will be able to copy it when you do. – VGR Mar 22 '18 at 16:04
  • The `Runtime` class can start a subprocess, and the returned `Process` object from `Runtime#exec(String)`, can create a in-/output stream to the subprocess. Not sure how you'd achieve the "covertness" of the file's existence, it's just... not plausible, unless it's deployed on a separate system, and then data is tunneled through e.g. a socket. – Kristin Mar 22 '18 at 16:10

1 Answers1

0

JAR is usual compressed file, you can put anything in it. Including exe files. You can execute command line commands via Java like this:

Running Command Line in Java.

So in theory you can extract the exe from your JAR and execute it via command line, read the command line output and continue based on this. About a guarantee that user will not just extract the EXE manually himself - There are no means of doing this in a reliable way. So if your intention is to wrap some other program and limit it's functionality with your wrapper then this is not the way to do it.

Tarmo
  • 3,851
  • 2
  • 24
  • 41