• Post Reply Bookmark Topic Watch Topic
  • New Topic

problem using Runtime class  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm using Runtime class to shoot a command on a unix system as :

Runtime runtimeObj = Runtime.getRuntime();

String command = "cat"+" "+logFileName+"|grep 49="+senderCompId+"|grep 60="+date+"|grep 1="+acctName+"|wc -l";

Process procObj = runtimeObj.exec(command);

procObj.wait() returns a non-zero value where it shud return zero as expected
The command runs succesfully on unix.

What could be the error?
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

That's not a command -- that's a pipeline (multiple commands.) Runtime.exec() doesn't interpret metacharacters like "|" or ">". If you want that, you have to run a shell to do that interpretation, and pass your pipeline to the shell; i.e., something like



[/code]
 
Abhishek Nigam
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tx...i like this place already!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!