Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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.

--
Regards
- Samar


Comment on Re: Handling returns from mkdir.
Select or Download Code
Re^2: Handling returns from mkdir.
by marto (Chancellor) 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.

      --
      Regards
      - 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)....im 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
        • ENAMETOOLONG
        • 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://879000]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (9)
As of 2014-08-28 23:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (275 votes), past polls