• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using a JAR resource file In a Runtime.GetRuntime().. cmd command  RSS feed

 
Nikolas Nikolaou
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I have a JAR app that requires piping a powershell file from the command line using the Runtime.getRuntime().exec

I know how to access a resource from within a JAR but In this case , I'm not sure how I can run the below command.

Do I need to get the resource as a file and somehow use the filename In the cmd String ?


 
Knute Snortum
Sheriff
Posts: 4087
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe to do this, you need to use to methods from process. First, wait for the process to finish:

Then read the output from the InputStream.
 
Stephan van Hulst
Saloon Keeper
Posts: 7820
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://www.javaworld.com/article/2071275/core-java/when-runtime-exec---won-t.html
 
Nikolas Nikolaou
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
I can run the command If I place the script file In the same folder as the JAR file.

I would like to place the script file within the JAR and run the same command.
 
Stephan van Hulst
Saloon Keeper
Posts: 7820
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't. The shell needs access to the script. A solution is to create a temporary folder, copy the script to that folder, invoke it with the shell, and then remove the temporary folder.
 
Nikolas Nikolaou
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean Powershell needs access to the script ?

The code Is being typed In CMD and piped Into powershell so It doesn't need direct access If that's what you mean.

Sorry , I may have not understood correctly.
 
Stephan van Hulst
Saloon Keeper
Posts: 7820
142
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you're passing script_v1.ps1 as if it refers to a file, but it doesn't. Unless powershell knows how to find resources within jar files, you will have to first extract the resource from the jar yourself.
 
Nikolas Nikolaou
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the Info guys.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!