aspose file tools*
The moose likes I/O and Streams and the fly likes Running external application with stdin as argument Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Running external application with stdin as argument" Watch "Running external application with stdin as argument" New topic
Author

Running external application with stdin as argument

ANIBAL RADWEN
Greenhorn

Joined: Dec 19, 2007
Posts: 2
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

Joined: Oct 29, 2001
Posts: 8866
    
    8

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.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
ANIBAL RADWEN
Greenhorn

Joined: Dec 19, 2007
Posts: 2
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

Joined: Oct 29, 2001
Posts: 8866
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running external application with stdin as argument