Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Handling returns from mkdir.

by samarzone (Pilgrim)
on Dec 24, 2010 at 08:32 UTC ( #879000=note: print w/replies, xml ) Need Help??

in reply to Handling returns from mkdir.

mkdir does not give any standard output. In case of failure of mkdir you see the error output which is not returned by backtick (``) operators. You may have to redirect error output to standard output to capture it.

my $op = `mkdir winlog 2>&1`;

On my system the error message in case of pre-existence of directory is "cannot create directory `winlog': File exists" which will fail your regular expression. I think using the return codes is a better idea than using the error output. You can get the return code in $?

For all codes returned by the mkdir check the detailed manual of the command

Update: As pointed by corion and marto below mkdir of perl is the correct option. My answer is more concerned with the way of getting output rather than the approach.

- Samar

Replies are listed 'Best First'.
Re^2: Handling returns from mkdir.
by marto (Bishop) on Dec 24, 2010 at 09:24 UTC

    Perl has a mkdir function built in, there's no need to rely on an external command.

      You are right. In the above answer I was just concerned with the way of output. I should have thought on the approach itself.

      Thanks marto.

      - Samar

      Hi marto,

      Thats actually what I was looking for..managed to use the built in command instead.

      I have been trying to find other errors reported by $!(File exists being the only one that kept coming up with the code), without any luck.

      I know this sounds pretty silly but, can you please tell me how i can find them(maybe a list of some sort) still a newbie.

      Thanks for all the help so far!!

        On the system documented by this man page, mkdir can return the following:
        • EACCES
        • EEXIST
        • EFAULT
        • ELOOP
        • ENOENT
        • ENOMEM
        • ENOSPC
        • ENOTDIR
        • EPERM
        • EROFS

        Those constants are provided by Errno and via %!. Don't rely on the stringification except for display purposes, because that depends on the system's locale.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://879000]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2018-03-24 10:39 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (298 votes). Check out past polls.