Monks,
I'm working with a script for a filter driver, what I want is to have some activity happen on each system call, by creating directories/files, modifying them or copying them. The script I have seems to be constantly dying on each system call, though it seems to successfully execute. What I have is something like the following (though the original has a Usage function for the Help command line option, but I removed it for this example:
use strict; use Cwd; use Getopt::Long; my ($help) = 0; my ($num) = 20; # Number of default loops to run my ($testdir) = ""; my ($verbose) = 0; GetOptions('help|?' => \$help, "num=i" => \$num, "testdir=s" => \$testdir, 'verbose' => \$verbose); # 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); # Set up test dirs if they do not exist if (!-d "test") { mkdir("test"); } if (!-d "test1") { mkdir("test1"); } # Change to the test area chdir("test"); # 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 die "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 die "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 > o +ut.txt"); if (-e "out.txt") { unlink("out.txt"); } } else { system("/bin/mv copieddirectory$dir ../test1/moveddirectory$di +r") or die "Could not move directory$dir: $!\n"; } # Delete the copied directory if ($^O =~ /Win32/) { rmdir("..\\test1\\moveddirectory$dir"); } else { system("/bin/rm -r ../test1/moveddirectory$dir") or die "Could not remove moved 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 die "Could not remove di +rectory$dir: $!\n";; } }
My initial failure comes on the first copy command, it fails with - Could not copy directory0 to copieddirectory0: A file or directory in the path name does not exist. Looking at the directory I see the directories there, with the right timestamps, but somehow system seems to get a failure on the call. Is there something that might generate a problem with the call as it is, especially since I am flushing calls to disk?
Thanks!

In reply to System call constantly dying by gokuraku

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.