0

I want to execute a script file from Java , so i have used the following lines of code to execute the script file.

Runtime rt = Runtime.getRuntime();          

Process proc = rt.exec("/home/akshay/NetBeansProjects/testapplication/src/test_script");

But runtime.execute("path/to/file/") requires String as parameters which is path to the file , but i need to include the script file in the Jar.

So please help to how to include a script file inside the jar and also what parameters should i provide in the runtime.execute("please specify what parameters should i supply when i copy and paste the script files in the current pacakge")

sampat nayak
  • 123
  • 2
  • 12
  • You can not execute a script that resides inside a JAR file. You have to extract it and the execute it. – Robert Oct 14 '16 at 07:45
  • Related : http://stackoverflow.com/questions/11339979/how-to-execute-script-from-jar-file, and http://stackoverflow.com/questions/6603807/executing-a-shell-script-inside-a-jar-file-how-to-extract for Linux scripts. – Yassine Badache Oct 14 '16 at 07:48

1 Answers1

1

Runtime.exec requires a command name that can be interpreted by the operating system, and neither Windows, Linux or Mac OSX are capable of executing a command directly out of a JAR file (or a ZIP file or a TAR file, or ...)

You will need to extract the script file from your JAR file into the file system and then run the script from the file.


In theory, you could get the OS to mount the JAR file as a filesystem. However, this is liable to not work due to issues with file locking ... assuming that the JAR file is also on your application's classpath.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216