in reply to Re: System call constantly dying
in thread System call constantly dying
use strict; use warnings; use Cwd; use Getopt::Long; my ($help) = 0; my ($num) = 20; # Number of loops to run my ($testdir) = ""; my ($verbose) = 0; GetOptions('help|?' => \$help, "num=i" => \$num, "testdir=s" => \$testdir, 'verbose' => \$verbose) or &usage(); &usage() if $help; # Header print "Beginning Directory Manipulation Testing...\n" if $verbose; $| = 1; # Get the current working directory my $home_dir = getcwd; # Change to the test directory chdir($testdir) or die "Can't make $testdir: $!\n"; # Set up test dirs if they do not exist if (!-d "test") { mkdir("test") or die "Can't make $testdir\\test: $!\n"; } if (!-d "test1") { mkdir("test1") or die "Can't make $testdir\\test1: $!\n"; } # Change to the test area chdir("test") or die "Can't change to test directory: $!\n"; # Directory Manipulation for (my $dir = 0; $dir < $num; $dir++) { # Make the directory if (!-d "directory$dir" ) { mkdir("directory$dir", 0755) or die "Can't make $testdir\\test +\\directory$dir: $!\n"; } # Change permissions of the directory if ($^O =~ /Win32/) { print "\nRunning chmod from - $home_dir\\..\\..\\bin\\chmod on + $testdir\\test\\directory$dir.\n" if ($verbose); if ($verbose) { system($home_dir . "\\..\\..\\bin\\chmod -v a+rwx $testdir +\\test\\directory$dir"); } else { system($home_dir . "\\..\\..\\bin\\chmod a+rwx $testdir\\t +est\\directory$dir"); } } else { system("/bin/chmod 777 directory$dir"); or warn "Could not chmod directory$dir: $?\n"; } # Copy the directory if ($^O =~ /Win32/) { print "\nRunning $home_dir\\..\\..\\bin\\cp on $testdir\\test\\directory$dir.\n" if ($verbose); system("$home_dir\\..\\..\\bin\\cp -rv directory$dir copieddir +ectory$dir"); } else { system("/bin/cp -r directory$dir copieddirectory$dir"); or warn "Could not copy directory$dir to copieddirectory$dir +: $?\n"; } # Rename the directory if (!-d "copieddirectory$dir") { print "copieddirectory$dir does not exist!\n" if $verbose; } if ($^O =~ /Win32/) { system("move copieddirectory$dir ..\\test1\\moveddirectory$dir + > out.txt"); if (-e "out.txt") { unlink("out.txt") or die "Can't unlink out.txt: $!\n"; } } else { system("/bin/mv copieddirectory$dir ../test1/moveddirectory$di +r"); or warn "Could not move directory$dir to test1: $?\n"; } # Delete the copied directory if ($^O =~ /Win32/) { rmdir("..\\test1\\moveddirectory$dir"); } else { system("/bin/rm -r ../test1/moveddirectory$dir"); or warn "Could not remove test1\\directory$dir: $?\n"; } # Remove the directory if ($^O =~ /Win32/) { rmdir("directory$dir") or die "Can't remove directory: $!\n"; } else { system("/bin/rm -r directory$dir"); or warn "Could not remove directory$dir: $?\n"; } } print "complete!\n" if ($verbose); # Change back to the top directory chdir($home_dir) or die "Can't move back to $home_dir: $!\n"; sub usage { print " $0 [options] Options: -num The number of loops to run, default $num -testdir Location to run the test within -verbose Run with messaging \n"; exit(0); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: System call constantly dying
by graff (Chancellor) on Jul 30, 2008 at 03:03 UTC | |
by gokuraku (Monk) on Jul 30, 2008 at 17:07 UTC | |
by graff (Chancellor) on Jul 31, 2008 at 03:44 UTC |