![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| some information on error checking | vinayrao | Shell Programming and Scripting | 1 | 03-14-2008 12:07 PM |
| Need help with error checking | xianoth | Shell Programming and Scripting | 0 | 08-31-2007 12:47 PM |
| Error Checking Problem | pokeycam | Shell Programming and Scripting | 4 | 09-13-2006 04:38 AM |
| error checking in bash | gubten | Shell Programming and Scripting | 3 | 06-06-2006 05:38 PM |
| Code checking for all values in the same if statement. | oracle8 | Shell Programming and Scripting | 4 | 01-23-2004 09:30 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Error code checking
I'm trying to create a directory from my Perl script. Only if the there was an error I want to let the user know about it. So if the folder exists is ok.
This is what I think should work: `mkdir log 2>/dev/null`; if($? == 0 || $? == errorCodeForFileExists) { everyting is fine } else { print "Error creating log directory. Check you file permissions\n"; exit(0) } The problem is that I'm getting the same error code for both File exists and Permission Denied. Any ideas? |
|
||||
|
I'm doing it in perl
Sorry if I wasn't clear.
I need to create a folder and if there is any errors like permission errors I want to let the user know about it. However I don't wish to overwrite the folder if it already exists. Also I need to do it inside a Perl script. This is the workaround I came up with: `ls log 2> /dev/null`; #check if the folder exists if($?) { #if it doesn't create it `mkdir log`; $dirFlag = 1; #flag to know that dir was created } The bad thing about this is that it wont let the user know if there were any permission errors. In other words, if the folder wasn't created for some reason the program will crash later when I try to write to that folder. So what I want to do is to somehow check, in my Perl code, the error code that UNIX spits out. The problem is that I'm getting the same error code number for both "File Permission" and "File exists" errors. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|