Re: ' du' command failing



On Jun 13, 9:14 am, Ravikanth <rkanth....@xxxxxxxxx> wrote:
Hi all,

I 've had a problem executing 'du -sk' command from a 'tclsh' shell.
From my understanding, 'du' command does not give the size of a
directory if the directory does not have a Read or Execute permission.
I changed to a directory which has some subdirectories out of which
some sub-directories do not have Read and Execute permissions.
From UNIX command line i have executed 'du' command.
from the result i found out that the size for the sub-directory
which does not have read and execute permission is not getting
displayed.

Now from UNIX command line i swithced onto a tclshell using 'tclsh'
command
and i tried to execute 'du' command
My problem here is 'du' is not functioning the same way as executed in
unix command line..
instead it is reporting like 'CHILD PROCESS EXITED ABNORMALLY'. I
tried to execute the same from a tcl script executing 'du' command in
catch block of statements.. but still i found the same error caught..
'CHILD PROCESS EXITED ABNORMALLY'..

How do i handle this situation.. Please help me out in this regard.

You're being hit by the fact that du writes to its stderr when it
reports the access problems. From [exec] manpage:

If any of the commands writes to its standard error file and
that standard error isn't redirected, then exec will
return an error;

Then the accepted optimum is to tell [exec] to be transparent on
stderr (ie routing the child's stderr to tclsh own current stderr, so
that you can see it in real time when it's a terminal for example):

exec du -sk ... >@ stderr

Now, you're not saved yet :-}
Doing so still leaves the post-mortem check in [exec]: at the end of
du's execution, [exec] will still report an error if the exit status
was non-zero, which is notably the case when du has encountered access
problems here and there. Here it is too bad since it happens only at
the end of du's life, well after it has written interesting data to
its output, but Tcl will still report the whole as an error (mixing
the child's stdout and Tcl error message in the error report):

% catch {exec du -sk aaa 2>@ stderr} err
du: cannot read directory `aaa/bbb': Permission denied
1
% puts $err
8 aaa
child process exited abnormally

To solve this second issue, two options:

(1) You know the output format enough to rip off the error message at
the end (that's doable only because du's output is made of whole
lines)

(2) You hide the exit status from Tcl by using a shell:

set x [exec sh -c {du -sk aaa;exit 0} 2>@ stderr]

HTH,

-Alex
.



Relevant Pages

  • Re: Sleep freezing
    ... >> man exec. ... > form of a standard shell pipeline where each arg becomes one ... > word of a command, and each distinct command becomes a sub- ... The word "execute" means to replace the program running in the calling ...
    (comp.unix.shell)
  • [Full-Disclosure] Advanced usage of system() function.
    ... and call its arguments as a command for shell. ... as we can see we still didnt get what we want (typing exit ... Connection closed by foreign host. ... think what we want to execute. ...
    (Full-Disclosure)
  • Advanced usage of system() function.
    ... and call its arguments as a command for shell. ... as we can see we still didnt get what we want (typing exit we are ... Connection closed by foreign host. ... think what we want to execute. ...
    (Bugtraq)
  • Re: Wait for background processes to complete
    ... To be able to execute commands in the background and wait for their ... The documentation I am referring to is http://perldoc.perl.org/. ... You can run a command in the background with: ... There is a general problem with perl documentation: ...
    (comp.lang.perl.misc)
  • RE: COMMAND field of TSO LOGON panel
    ... The issue is that the logon proc being executed directly launches into ISPF, ... If you exit ISPF, allow the exec to run, then reenter ISPF ... COMMAND field of TSO LOGON panel ... However,it didn't execute it. ...
    (bit.listserv.ibm-main)