Click to See Complete Forum and Search --> : make directory on Windows machine with Perl script


crmpicco
06-20-2006, 10:21 AM
#!C:/Perl/bin/perl.exe

$new_dir = "Bob";
$perm = 755;
makeDir();

sub makeDir {
mkdir ($new_dir,$perm) or "Error making Directory ($new_dir)\n";
exit();
}

print "Content-type: text/HTML\n\n";


I am attempting to create a directory (called Bob) with this Perl script, however, it doesnt seem to be working. I have managed to create a file and write to it with another script, but this one doesnt seem to be working at all.

I am just presented with this error:

=====================================================
CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:
=====================================================

robertketter
06-21-2006, 10:06 PM
#!C:/Perl/bin/perl.exe

$new_dir = "Bob";
$perm = 755;
makeDir();

sub makeDir {
mkdir ($new_dir,$perm) or "Error making Directory ($new_dir)\n";
exit();
}

print "Content-type: text/HTML\n\n";




Here is my way of doing this...

#!C:/Perl/bin/perl.exe

$new_dir = "Bob";
$perm = 755;
makeDir();

sub makeDir {
if (-e "$new_dir"){ problem("Directory (<b> $new_dir </b>) already exists.\n") } # Checks for existing
mkdir ($new_dir,$perm) || problem("Error making Directory (<b> $new_dir </b>)\n");
print "Content-type: text/html\n\n";
print "<p>(<b> $new_dir </b>) Directory has been created.\n";
exit();
}# end sub makedir

sub problem{
# I always make my own sub to report problems. I find it alot easier to understand
# an error if I explain what happened in my own words.
print "Content-type: text/html\n\n";
print "$_[0]\n";
exit;
}# end sub problem

Let me know if you need more help.... Robert Ketter, www.robertketter.com