• Post Reply Bookmark Topic Watch Topic
  • New Topic

problem executing a unix command in java runtime

 
Richard Vagner
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I got stuck on this.... I am trying to get a file size from a unix comand and I have tried to execute it in java runtime but it is not working.
here is the code:



Can anyone throw some light on this? Please.
 
Rob Spoor
Sheriff
Posts: 20817
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This is not one process, but one process that redirects its output to another process.

What you need to do is the same. Create one process that executes "ls -l /home/test/myzip.zip", another process that executes "awk '{print $5}'", and then redirect the output (getInputStream()) of the first process to the input (getOutputStream()) from the second process.

You could try to do the latter by just reading from the input stream and writing to the output stream, but I tried that once and couldn't get the second process to run until I closed the input stream from the first process. Perhaps I forgot to flush, but I can't remember.
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you need to get the file size with a Unix command? Why do you simply use the File class to get the file size?
 
Richard Vagner
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob, thanks so much. Now I know why it is not working. I will follow your suggestion and give it try.


Edwin, I actually have a requirement comparing the file size from this our server to a file from remote server. The only command I can use to get the file size from remote server is like:

ssh theuser@222.22.222.222 ls -l test/myzip.zip |awk '{print $5}'

So I thought the only way to get the file size from remote server and then compare it to the file size from our server.

Am I far off the track?

I really appreciate your input.
 
Richard Vagner
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bob,

I am new to this. Could you provide an example of "redirect"? Thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!