mricci has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,
I am attempting to create a directory from UNIX using a SAMBA mount to windows box. I have a parent script which calls a child script, the parent script creates the directory just fine.
However the second script which is a child process, does the exact same thing however when passed in it is given a new name for the directory that is to be created. Oddly enough it did not create the directory nor did it die. It appears is if perl thinks everything worked fine.
Has anyone experienced this before? Any help would be wonderful
Please find the code below.
Script 1
<code>
use strict;
use File::Path;
my $dirStr = '/Path/To/Directory/Dir1';
unless (-d $dirStr){
mkpath ($dirStr, 1, 0777) or die("Directory $dirStr does not exist and cannont be created");
print "Makeing First Dir from Parent Script\n";
my $command = "perl /usr/local/users/myuser/createdir2.pl";
open(TEST, "|$command");
}
<code>
Script 2 "createdir2.pl"
<code>
use strict;
use File::Path;
my $dirStr1 = '/Path/To/New/Directory/Dir2';
unless (-d $dirStr1){
mkpath ($dirStr1, 1, 0777) or die("Directory $dirStr1 does not exist and cannont be created");
print "Makeing Second Dir from Child Process\n";
}
<code>
Thanks in advance

Replies are listed 'Best First'.
Re: Child Process and SAMBA
by kyle (Abbot) on Feb 05, 2008 at 21:25 UTC

    Do you get the output from both print statements? Are you sure that script 2 runs?

    At the end of script 1, you use open to execute script 2. This should work, but you don't really check. If you really do need to pipe something to script 2, check the open in script 1:

    open(TEST, "|$command") || die "Can't pipe to '$command': $!";

    If you do not need to pipe anything to script 2, then system would be a more straight-forward way to do what you're trying to do.

    if ( 0 != system( $command ) ) { die "system() exited with status $?"; }

    Since your code blocks have an extra unbalanced brace in them, I'm wondering if these are part of a larger program and whether you've actually run the test scripts as you've written them here.

      Thanks a bunch for your insight...
      As it turns out after further investigation this does not appear to be a perl issue at all.
      If I attempt to do the same thing locally things work just fine, however going across the SAMBA mount shows the issue.
      I believe that the real problem lies within SAMBA so I am going to research there.. If I find an answer or solution I will certainly post so others that run into this don't have the same problem..
      Thanks again for your insight :)
Re: Child Process and SAMBA
by moritz (Cardinal) on Feb 05, 2008 at 21:25 UTC
    open(TEST, "|$command"); is a strange way to execute a command, since you don't feed any input into it.

    Recommended ways are exec, system and for other perl scripts do.

    Have you checked if the second script runs at all?

    And it feels almost too stupid to ask.. but have really checked that the second dir doesn't already exist?

      Thanks and yes I know that exec or system are better ways.
      I was just throwing some quick code together to attempt the same thing a larger script does.
      I did in fact check to see if it worked and if the second script actually executed.. But your points are good ones.
      Thanks again and you can read my reply to the first reply in the thread as I believe this is a SAMBA issue not a perl issue...
      Thanks :)