• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Having trouble in running a unix command and getting the output

 
Suraj Shekar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to run a unix command from within the java code. I am not able to make it work. I am enclosing the code and the error message that I am getting. Any help is highly appreciated.




The error message that I am getting is

Here is the standard output of the command:

SLu|%%$$=
Here is the standard error of the command (if any):

cat: cannot open |
cat: cannot open A_UNIX_PROGRAM
cat: cannot open -d



Looks like the cat command is working and not the pipe command and the command after the pipe. But when I run the UNIX command from the command prompt I get the expected result.

I am running this program on AIX UNIX machine.
 
Joe Ess
Bartender
Posts: 9318
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you run the command from the shell, the shell interpreter understands that you want to run one program and pipe the output to another. When you use Runtime.exec, it takes the entire command line and throws it at cat. Cat tries to open files like "|" and "-p" and fails. You have to exec the shell and pass it the command as arguments or through standard input. Here is a good article on using Runtime.exec and the pitfalls it contains.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic