[EMAIL PROTECTED] wrote:
> Hi!
> 
> I have a Perl script that opens a number of DBM files. It also starts
> other programs via calls to "system". I recently found out that the
> "handles" to the DBM-files seem to be inherited by the newly started
> process. I would like to avoid this. Does anybody know how to do this?
> 
> To demonstrate my "problem" I wrote the little script given below. It
> uses "notepad" as an example of an external program that will inherit
> the filehandles. To run the example I did:
> 
>   c:\> perl start-notepad.pl
>           -----> Press Ctrl-C to terminate the Perl script.
>   Terminating on signal SIGINT(2)
>   c:\>
>   c:\> rm -f foo-dbm.dir foo-dbm.pag
>   rm: cannot unlink entry "foo-dbm.dir": The process cannot access the
> file because it is being used by another process.
>   rm: cannot unlink entry "foo-dbm.pag": The process cannot access the
> file because it is being used by another process.
>   c:\>
> 
> After terminating "notepad" I can remove the DBM files without problems.

Try detaching the process and not inheriting :

use strict;
use warnings;
use Fcntl;
use SDBM_File;
use Win32::Process;

my $file = "foo-dbm";

tie my %h, "SDBM_File", $file, O_RDWR|O_CREAT, 0666
     or die "Create '$file': $!($^E)";

my $editor = 'D:\\Program Files\\Windows NT\\Accessories\\wordpad.exe';
if (0) {
        system "$editor web.txt";
} else {
        my $pObj = CreateProcess ($editor, 'wordpad web.txt', 1);
}
sleep 10;

sub CreateProcess {
        my ($exe, $cmdline, $detach) = @_;

my $pObj;
Win32::Process::Create ($pObj, $exe, $cmdline, 0, $detach ?
   DETACHED_PROCESS : NORMAL_PRIORITY_CLASS, '.') or
   die "Win32::Process::Create: $!($^E)";
return $pObj;

}

__END__
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to