Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running external application with stdin as argument

 
ANIBAL RADWEN
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
 
Joe Ess
Bartender
Pie
Posts: 9265
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
Pie
Posts: 9265
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic