This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

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

 
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 ?


 
Marshal
Posts: 5995
156
Chrome Eclipse IDE Java Postgres Database Ubuntu 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.
 
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: 10249
216
  • 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: 10249
216
  • 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.
 
I promise I will be the best, most loyal friend ever! All for this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!