Win a copy of Rust Web Development this week in the Other Languages 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

Running external application with stdin as argument

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

I have a problem running an external application using java.
This application takes as argument a filename used as argument here is argument :
./command < inputfile

note here we use "<" as a redirection for the program.

How can I run this command line from java code since i tried to use it like string to lauch with exec() but in vain, it seems like Java don't like the reidrection symbols

Any help please
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Javaranch. You must have overlooked our naming policy on the way in. In short, your name must be a real-sounding first and last name separated by a space.
As for your question, when you do input or output redirection on a command line, the command interpreter (or shell in *nix) is what does the redirection. You either have to exec to a shell (i.e. "bash command < inputfile", just a wild guess, I dont know the exact syntax) so it can do the indirection or use Java to read the file and input it to the Process object's input stream.
 
ANIBAL RADWEN
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the name.
Do you mean I have to write my command line with redirections into a shell script i run with java ?
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could try that. You could also try executing the shell and passing your program as an argument to the shell (as I detailed before).
Here is an article that details the problems with Runtime.exec and the workarounds.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic