Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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: 74783
336
  • 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.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic