I am having difficulties with Win32::Process and filehandles used therein.
This is a condensed version of the script I am writing:

use Win32::Process;
$Exe = "C:\\foo\\foo.exe";
$Args = "foo.exe arg1 arg2";

close STDOUT || die "Error closing STDOUT: $!";
open(STDOUT, ">>stdout.txt") || die "Error redirecting STDOUT: $!";
Win32::Process::Create($Obj, $Exe, $Args, 1, THREAD_PRIORITY_NORMAL, ".");
sleep 5;
$Obj->Kill($exitcode);
close STDOUT || "Error closing STDOUT: $!";
rename("stdout.txt", "renamestdout.txt") || die "Error renaming: $!";

$Exe is a process that logs to STDOUT, which I want  redirecting to the
file stdout.txt, and then after a period of time (in this example 5
seconds), kill $Exe and rename stdout.txt.

The trouble is that the rename is failing, with error "Permission denied".
I believe the reason why is because the $iflags Win32::Process::Create
parameter is set to 1, and after the process is killed, $Obj is still
retaining a lock on the STDOUT handle.  Does anyone know how I might be
able to remove this lock, so stdout.txt can be renamed?

Thanks in advance,

Phil Morley



_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to