Finding the Current Working Directory
The current working directory when applied to CGI programs is:
- The default directory where the program will look for files when no directory path was specified with the file name.
- The base directory the program will assume when relative directory paths are specified.
For Unix/Linux servers, the current working directory usually is the directory where the CGI program is installed and running in.
But it's not always the case. Servers can be configured in a multitude of different ways.
When a CGI script doesn't find a file you know is where you specified it to be, it may be that the current working directory is not what you think it is.
The following short script can determine the current working directory for you.
(Master Pre-Installation Tester can be used instead if you prefer not to create your own testing script.)
#!/usr/bin/perl use strict; use Cwd; my $dir = getcwd; print "Content-type: text/html\n\n"; print "Current working directory is:
"; opendir D,'.'; my $d = join '
$dir
',readdir D; print 'Listing of current working directory is:
';
',$d,'
Install the above script where CGI scripts can run (e.g. the cgi-bin). If testing for the current working directory that another script is using, install the above in the same directory as the other script.
Use a plain text word processor like NotePad or TextWrangler when copying the above script and saving it to a file. Use an FTP program to upload the file to your server, uploading it as a plain text file, not as a binary file. Then give the uploaded file 755 permissions.
Type the URL of the script into your browser to obtain the current working directory.
Will Bontrager