• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Runtime.exec() method not executing correct command?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm building a simple app to execute a database application (UNIX) that takes several parameters. The full text of the command I'm executing is below:

tbuild -f /homecses/micsedev/mods/tpt/case_coop_stage.tpt -v /homecses/micsedev/connections/cse_batch_drbc.con -R /homecses/micsedev/logfiles/tbuildlogs/chkpoint -L /homecses/micsedev/logfiles/tbuildlogs -u "FloadIn='/homecses/micsedev/data/in/case_coop.dat'" case_coop_stage



When I paste this exact command into my OS, it runs without issue. However, if I use this exact command as a string in my Java app and pass it into Runtime.getRuntime().exec([command]), I get an error message back from the tbuild application which indicates that certain arguments are getting removed. Specifically, it appears that my "FloadIn" value is not being used (the value passed to the -u switch). That value requires that the double quote characters be included (and when I build the command, I make sure to escape the quote characters, and have verified this through println()).

I know that commands are broken by whitespace when passed to the exec() method as a full string, but with this command there is no additional whitespace to break on. How can I tell exactly what command is actually being passed to my OS? After building the above command, I have the following code:



Again, when I manually execute the command that the println() prints, I have no issue. But when the exec() method uses that command, it fails (not through Java, but through the tbuild program I am trying to execute).

Any ideas?
 
lowercase baba
Posts: 13082
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you post your exact code on how you build the string?
 
Kevin Brydges
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In this example, args[0] is "case_coop".



I also tried using a ProcessBuilder, and had the exact same results:

 
Saloon Keeper
Posts: 14505
325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at the exec() documentation: http://download.oracle.com/javase/6/docs/api/java/lang/Runtime.html#exec(java.lang.String[]).

The parameters need to be added as separate array elements.

[edit]

Forum breaks my links -_-;
 
Kevin Brydges
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Take a look at the )]exec() documentation. The parameters need to be added as separate array elements.



That's why I tried the ProcessBuilder method, which gave the same error result.
 
Sheriff
Posts: 22701
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure you still need those quotes in "\"FloadIn='" + DAT_PTH + "/" + args[0] + ".dat'\"". I think that those quotes are for the shell to indicate the following should be treated as one single parameter, and not be processed. Try removing them:
 
Kevin Brydges
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:I'm not sure you still need those quotes in "\"FloadIn='" + DAT_PTH + "/" + args[0] + ".dat'\"". I think that those quotes are for the shell to indicate the following should be treated as one single parameter, and not be processed. Try removing them:



That was it! Thank you very much everyone.
 
Rob Spoor
Sheriff
Posts: 22701
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
 
Space pants. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic