• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with Runtime.exec()

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

I have the following problem with Runtime.exec().



Now, my requirement is :
Inside RunFile.cmd I want to execute another file whose path is given by user.

So I need to pass an argument of the path of file selected by user to this RunFile.cmd.

Please help how can i achieve this.


Thanks,
Manish Ramrakhiani
 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Manish Ramrakhiani wrote:Hello All,

I have the following problem with Runtime.exec().



Now, my requirement is :
Inside RunFile.cmd I want to execute another file whose path is given by user.

So I need to pass an argument of the path of file selected by user to this RunFile.cmd.

Please help how can i achieve this.


Thanks,
Manish Ramrakhiani



Something like this (assuming that this is in main)


 
Manish Ramrakhiani
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Shashank for your reply.

However this is not working.

I tried :


but it is throwing me an error that it cannot find the file specified because it is appending args[0] too as the file name.

Please help.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wouldn't it be clearer to use one of the exec() method which takes an array of arguments?
See the java.lang.Runtime JavaDocs.

Carefully study the java.lang.Process JavaDocs for the requirement to consume the stdErr and stdOut streams - many people get stuck due to not handling these streams correctly.

Bill
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also google for when Runtime.exec() won't by Michael Daconta.
 
Manish Ramrakhiani
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks all for your replies.
I could solve the problem finally.

I did the following:

.

And isnide this abc.cmd I wrote %1, which typically means that %1 should be replaced by the first argument.

So on and so Forth for %2 etc..

Thanks,
Manish Ramrakhiani.
 
Time is the best teacher, but unfortunately, it kills all of its students - Robin Williams. tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic