Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning 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
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Problem with Runtime.exec()

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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: 70694
288
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Is that a spider in your hair? Here, threaten it with this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic