• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

process builder problem

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greetings,

I am working on a jsp application and at some point I need to execute a terminal command within java code.
Although the exact command works in terminal(osx), it returns a application specific error when I try it in java. (I interpreted this as I can reach the .jar file and execute it yet there's somehow a problem while passing the parameters).
I tried both runtime.exec() and processbuilder.start() options.
Any help will be highly appreciated
Below is the command and the code I have been working on:

command:

java code (both with processbuilder and runtime.exec())
 
Ranch Hand
Posts: 121
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Emrah

Do you input your first command in a shell? If yes, then you do not need any additional quotes in parameters passed to a ProcessBuilder. Quotes are treated in a special way by the shell. They are used to properly pass some arguments. For example, shell treats ""{?s ?p ?o}" as single argument. Without quotes it would be three arguments. However, in ProcessBuilder you already have natural separation between arguments. Each string is treated as exactly one parameter. So in your code you should have "{?s ?p ?o}" instead of "\"{?s ?p ?o}\"". Same for "S".
 
Marshal
Posts: 80508
455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Thank you for using code tags, but the long lines make the post difficult to read. I have broken them; the first code block was originally one line. I have changed the // comments to /* comments */. I do not know whether line 6 of the second block is supposed to be inside the comment or not. I suspect not.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic