Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File still in use after "close FILE1"

Status
Not open for further replies.

MoshiachNow

IS-IT--Management
Feb 6, 2002
1,851
IL
HI,
my program writes to handle FILE1 and closes is properly once I'm done.
However the created file remains read only till I exit the whole application...
Why would it happen ?

Long live king Moshiach !
 
I'm unable to reproduce that behaviour; what OS, perl version, etc.?

Annihilannic.
 
Okay... in that case we need to know a bit more... is it under Cygwin? Strawberry perl? Some other perl distribution?

It sounds like a Windows-specific issue to me so you could be in trouble... I just tried it in Strawberry perl though using this script and was able to open, modify and save the output file using a text editor while the script was still running:

Perl:
#!/usr/bin/perl -w

use strict;
use warnings;

open(OUTFILE, '>MoshiachNow.out') or die "Can't open MoshiachNow.out $!";

print OUTFILE "a test\n";
close(OUTFILE);

sleep 300;

What application is telling you that the file is read-only?

Annihilannic.
 
No problems when I use MS Word either. I don't have ActivePerl handy to try that.

How about if you try my little script above... does it happen for you still, or is it only when you run your own script?

Annihilannic.
 
Hi

What happens if you add some instruction involving the filehandle, at the end of Annihilannic's code, after the [tt]sleep[/tt] :
Perl:
open(OUTFILE, '>MoshiachNow.out') or die "Can't open MoshiachNow.out $!";

print OUTFILE "a test\n";
close(OUTFILE);

sleep 300;

<OUTFILE>; # certainly will throw error, used just to keep it from being garbage-collected

Feherke.
 
no, even with a sleep it's not locked ...

The code is :

use strict;
#use warnings;

use File::Copy;
use POSIX ('strftime');
use Getopt::Long;
use Getopt::Std;
use PDF;
use threads;
use Win32;
use Win32::GUI();
use Win32::GUI::Constants;
use Win32::GUI::Constants::Tags;

my $SYSTEMDRIVE=$ENV{'SYSTEMDRIVE'};
my $WINDIR=$ENV{'WINDIR'};
my $TEMP=$ENV{'TEMP'};
$| = 1;

my $date1 = strftime "%Y%m%d", localtime;
my $time1 = strftime "%I_%M_%S", localtime;
my $TIME=localtime;
my $computer = Win32::NodeName;
my ($file,$good,@files,$filename,$creator,$pages,$line,$folder,$LOG,$DCS,$Preseparated,$path,$hires_old);
my ($booklets,$folder1,$filenameShort,$prefix,$VPStype,$Orientation,$counter9,$pagesPerBooklet,$VariablePagesPerBooklet);
my ($myfile,@current,$GTS_PPMLVDXVersion,$GTS_PPMLVDXConformance,$version,$NOofPages,$MediaBox,@pagedevice,$SPD,$counter);
my ($lastchunk,$buffer,$extention,$extention1,$height,$width,$BoundingBox,$producer,$dir,$hiresDirs,$hires,$pdf,$length,$filenamexcel);
my ($SplitLevel,$fileType,$sheetSize,$ppmlVer,$Dir,$y,$PPML,$PDF,$PS,$VPS,$AFP,$CJF,$VDX,$dir2,$extention2);
my ($main,$label14,$font,$font2,$font4,$buttonQuit,$buttonStop,$buttonStart,$font8,$font3,$label4,$buttonDir,$buttonDirOk);
my ($subroutine,$timeout,$thr,$stop,$fileSize,$header);

#define the command mode options
my %options;
my $OPTIONS=getopts('m:psinhrwd:x:',\%options);
our($opt_d,$opt_x,$opt_m);
my $INV = {};
my $lookup = {};
my $setPageDevice = {};
my $help =<<"EOH";
--------------------------------------------
$0: findPS.exe
Usage: findPS.exe -d <DIR> -x <EXTENTION> [-n] [-i]
Ex: findPS.exe -d "\\\\cilnetapp1\\POS\\2.Development" -x ps [-i] [-n] [-m 200]
-h = this help
-d = search dir name
-x = extention to be searched for
-n = file copy
-i = inventory
-r = remove file if has HiRes link
-s = skip already checked files
-p = skip unless setPageDevice
-m = minimum pages to process
-w = get width+height
Possible extensions : pdf,ppml,ps,vps,vdx,cjf,afp
--------------------------------------------
EOH

$|=1; #force flush

$dir2 = $options{d};
$extention2 = $options{x};
my $move = $options{n};
my $inventory = $options{i};
my $remove = $options{r};
my $skip = $options{s};
my $pagedev = $options{p};
my $minimum = $options{m};
my $widthHeight = $options{w};

#$extention = "ppml" unless $extention;
#print STDOUT "~~~~~~~~~~~dir=$dir2,extention=$extention2\n";

if ($options{h} || ( ! $dir2 && $extention2) || ( $dir2 && ! $extention2)){
die $help
} elsif ($dir2 && $extention2) {
&start_Click;
}

if ($inventory) {
#build inventory hash
my $total;
for (@current) {
chomp;
print STDOUT "$_\n";
#sleep 1;
$total++;
$filename = $_;
#print STDOUT "input=$filename\n";
$filename =~ m!.*\\(.*\.(ps|sep|PS|vps|VPS|vdx|VDX))!;
$filename = $1;
#print STDOUT "current=$filename\n";
$INV->{$filename}="1";
}
print STDOUT "Total files in inventory :$total\n" if $inventory;
#sleep 200;
}

#print STDOUT "++++++dir=$dir,extention=$extention=\n";
if (! $dir2 && ! $extention2) {
#print STDOUT "HERE1\n";
#define the main window if not in command mode
# Main GUI Window
$font = Win32::GUI::Font->new(-name => "Arial", -size => 8);
$main = Win32::GUI::Window->new( -name => 'Main',-width => 700,-height => 300,
-text => "customPrint Ver 1.33 on $computer",-pos => [ 400, 10 ]);
$font8 = Win32::GUI::Font->new(-name => "Arial", -size => 8,);
$font2 = Win32::GUI::Font->new(-name => "Arial",-size => 8,-bold => 1);
$font3 = Win32::GUI::Font->new(-name => "Comic Sans",-size => 8,-bold => 1);
$font4 = Win32::GUI::Font->new(-name => "Comic Sans",-size => 10);

$label4 = $main->AddTextfield(-text => "d:\\shared",-font => $font,-foreground => [0, 0, 0],
-pos => [ 10, $y ],-width => 580,-height => 30);
$buttonDir = $main->AddButton(-name =>'Dir', -text => 'Select',-font => $font2,-foreground => [0, 0, 0],
-pos => [ 590,$y ],-width => 50,-height => 28);
$buttonDirOk = $main->AddButton(-name =>'DirOk', -text => 'OK',-font => $font2,-foreground => [0, 0, 0],
-pos => [ 650,$y ],-width => 30,-height => 28);

$y +=40;

$PS = $main->AddRadioButton(-text => 'PS',-name => 'PS',-pos => [ 590,$y ], -checked=> 1);
$y +=20;
$CJF = $main->AddRadioButton(-text => 'CJF',-name => 'CJF',-pos => [ 590,$y ], -checked=>0);
$y +=20;
$VDX = $main->AddRadioButton(-text => 'VDX',-name => 'VDX',-pos => [ 590,$y ], -checked=> 0);
$y +=20;
$PPML = $main->AddRadioButton(-text => 'PPML',-name => 'PPML',-pos => [ 590,$y ], -checked=> 0);
$y +=20;
$PDF = $main->AddRadioButton(-text => 'PDF',-name => 'PDF',-pos => [ 590,$y ], -checked=> 0);
$y +=20;
$VPS = $main->AddRadioButton(-text => 'VPS',-name => 'VPS',-pos => [ 590,$y ], -checked=> 0);
$y +=20;
$AFP = $main->AddRadioButton(-text => 'AFP',-name => 'AFP',-pos => [ 590,$y ], -checked=> 0);
$y +=40;

# ALL/MM/\D'Haussy/Fenske1/Fenske2/Fenske3/Rotomail/Rotomail1/Rotomail2/Rotomail3/Rotomail4/CNAM/Siemens
$buttonStart = $main->AddButton(-name =>'start', -text => 'Start',-font => $font2,-foreground => [0, 0, 0],
-pos => [ 400, $y ],-width => 60,-height => 20 );
$buttonStop = $main->AddButton(-name =>'Stop', -text => 'Stop',-font => $font2,-foreground => [0, 0, 0],
-pos => [ 500, $y],-width => 60,-height =>20);
$buttonQuit = $main->AddButton(-name =>'Quit', -text => 'Quit',-font => $font2,-foreground => [0, 0, 0],
-pos => [ 600, $y ],-width => 60,-height =>20);
$main->Show();
Win32::GUI::Dialog();
#============================================================================
}

sub start_Click {
undef $extention if $main;
undef $dir if $main;

if (! $dir2 && ! $extention2) {
if ($Dir) {
$dir = $Dir;
} else {
$dir = "d:\\shared";
}

if ($PS->Checked()) {
$extention = "ps" ;
$extention1 = "\\\.ps \\\.sep" ;
$header = "FileName\tCreator\tPages\tWidth\tHeight\tpageDevice\tDCS\tPreseparated\tPath\n"; #print to log
} elsif ($VPS->Checked()) {
$extention = "vps" ;
$extention1 = "\\\.vps" ;
$header = "FileName\tCreator\tVPStype\tPages\tBooklets\tVariablePagesPerBooklet\tpagesPerBooklet\tOrientation\twidth\theight\tpageDEvice\tHiRes count\tOriginal path\tHiRes list\n"; #print to log
} elsif ($PDF->Checked()) {
$extention = "pdf" ;
$extention1 = "\\\.pdf" ;
$header = "FileName\tversion\tCreator\tProducer\tNOofPages\tWidth\tHeight\tOriginal path\n"; #print to log
} elsif ($AFP->Checked()){
$extention = "afp" ;
$extention1 = "\\\.afp" ;
$header = "FileName\tPages\tPath\n"; #print to log
} elsif ($CJF->Checked()){
$extention = "cjf" ;
$extention1 = "\\\.cjf" ;
$header = "FileName\tSplitLevel\tfileType\n"; #print to log
} elsif ($VDX->Checked()) {
$extention = "vdx" ;
$extention1 = "\\\.vdx" ;
$header = "FileName\tCreator\tProducer\tpages\tbooklets\tpagesPerBooklet\tGTS_PPMLVDXVersion\tGTS_PPMLVDXConformance\tpath\n"; #print to log
} elsif ($PS->Checked()) {
$extention = "ps" ;
$extention1 = "\\\.ps \\\.sep" ;
} elsif ($PPML->Checked()) {
$extention = "ppml" ;
$extention1 = "\\\.ppml" ;
$header = "FileName\tCreator\tPPML_Ver\tPages\tBooklets\twidth\theight\tpagesPerBooklet\tHiRes count\tOriginal path\tHiRes list\n"; #print to log
}
} else {
$dir=$dir2;
$extention = $extention2;
#print STDOUT "++++++++++++++dir=$dir,extention=$extention=\n";
if ($extention eq "ps" ) {
$extention1 = "\\\.ps \\\.sep" ;
$extention = "ps" ;
$header = "FileName\tCreator\tPages\tWidth\tHeight\tpageDevice\tDCS\tPreseparated\tPath\n"; #print to log
} elsif ($extention eq "vps" ) {
$extention1 = "\\\.vps" ;
$extention = "vps" ;
$header = "FileName\tCreator\tVPStype\tPages\tBooklets\tVariablePagesPerBooklet\tpagesPerBooklet\tOrientation\twidth\theight\tpageDEvice\tHiRes count\tOriginal path\tHiRes list\n"; #print to log
} elsif ($extention eq "vdx" ) {
$extention1 = "\\\.vdx" ;
$extention = "vdx" ;
$header = "FileName\tCreator\tProducer\tpages\tbooklets\tpagesPerBooklet\tGTS_PPMLVDXVersion\tGTS_PPMLVDXConformance\tpath\n"; #print to log
} elsif ($extention eq "ppml" ) {
$extention1 = "\\\.ppml" ;
$extention = "ppml" ;
$header = "FileName\tCreator\tPPML_Ver\tPages\tBooklets\twidth\theight\tpagesPerBooklet\tHiRes count\tOriginal path\tHiRes list\n"; #print to log
} elsif ($extention eq "pdf" ) {
$extention1 = "\\\.pdf" ;
$extention = "pdf" ;
$header = "FileName\tversion\tCreator\tProducer\tNOofPages\tWidth\tHeight\tOriginal path\n"; #print to log
} elsif ($extention eq "cjf" || $CJF->Checked()) {
$extention1 = "\\\.cjf" ;
$extention = "cjf" ;
$header = "FileName\tSplitLevel\tfileType\n"; #print to log
} elsif ($extention eq "afp" ) {
$extention1 = "\\\.afp" ;
$extention = "afp" ;
$header = "FileName\tPages\tPath\n"; #print to log
}
}

$dir=~ s!\w:!\\\\cilnetapp2\\neria-fserver\$! if ($dir !~ /c:|d:/i);

print STDOUT "dir=$dir,extention=$extention=\n";

if ($extention =~ m/vdx|ppml|vdx|ps|vps|pdf|cjf|afp/i ) {
$LOG="$SYSTEMDRIVE\\Documents and Settings\\All Users\\Desktop\\analize_$extention.$time1.xls";
} elsif ($extention !~ /cjf/) {
die "\nValid extensions are \"ps\",\"vps\",\"ppml\",\"vdx\",\"pdf\",\"cjf\" only !\n";
}
#force flush

system("dir /s /b \"$dir\\\*\.$extention\" > \"$TEMP\\$extention.$time1.txt\"");

#find /c "pdf" D:\Temp\pdf.12_49_25.txt
#---------- D:\TEMP\PDF.12_49_25.TXT: 4
$fileSize = `find /c "$extention" "$TEMP\\$extention.$time1.txt"` if (-f "$TEMP\\$extention.$time1.txt");
$fileSize =~ m!.*:\s*(\d+)!;
$fileSize = $1;
#print STDOUT "fileSize=$fileSize\n";
if ($fileSize eq 0) {
print STDOUT "No $extention files found in $dir !!\n";
if ($main) {
return;
} else {
exit 1;
}
}

#print STDOUT "HERE2\n";
print STDOUT "Log=$LOG\n";
open LOG,">$LOG"; #main log
select LOG;
#print STDOUT "header=$header\n";
print "$header\n" || warn "$!\n";;

# |findstr /v "VDP\\Support System_Wide_Workflows \\.dat \\.ind \\.xls \\.rsrc \\.db \\.jt \\.psd \\.html \\.lib \\.eps \\.tif \\.nct \\.h"|findstr /i "$extention1"`;
print STDOUT "Files:===================================\n";
open (FILE5,"$TEMP\\$extention.$time1.txt");
while (<FILE5>) {
chomp;
next if (/DirectSmile|images|Font_TestData|CustomerFilesJapanese|Dyna_ATM_CID|Load_Stress|Tali|05 multiple jobs|Copy\(|FromKnownBugs|font-|PODi_TestJobs|procsets|RIP NG DATA|Varimages|Book_of_One|
MissingResource|PPML_16_NOV_2010|16ST_318670_0001.p|newsletter|Image_File|RIP NG DATA|
Ghosting|MullerMartiniFiles|VariousPDFSINCMYK|XPl2003VariablePages|PDFImage|ppml contents_|CMYK_PPML|
SampleVariableDataFormats|HiRes|School PPML|ToppanJobBatchingProblem|SLN602|ImagesB5_Color|POSDM|
VDP\\Support|vote2|\.dat|reusableobject|images|\.ind|\.xls|\.rsrc|\.db|\.jt|\.psd|\.html|\.lib|\.eps|
\.tif|\.nct|\.h/i);
next unless (/\.$extention/i);
print STDOUT "$_\n";
}
close FILE5;

LABEL: open (FILE5,"$TEMP\\$extention.$time1.txt");
while (<FILE5>) {
if ($main) {
$main->DoEvents() >= 0 or die;
$main->Update();
}

if ($stop) {
undef $stop;
close LOG;
close FILE5;
last;
}
next if (/DirectSmile|images|Font_TestData|CustomerFilesJapanese|Dyna_ATM_CID|Load_Stress|Tali|05 multiple jobs|Copy\(|FromKnownBugs|font-|PODi_TestJobs|procsets|RIP NG DATA|Varimages|Book_of_One|
MissingResource|PPML_16_NOV_2010|16ST_318670_0001.p|newsletter|Image_File|
RIP NG DATA|Ghosting|MullerMartiniFiles|VariousPDFSINCMYK|XPl2003VariablePages|PDFImage|
ppml contents_|CMYK_PPML|SampleVariableDataFormats|HiRes|School PPML|ToppanJobBatchingProblem|
SLN602|ImagesB5_Color|POSDM|vote2|transformations|\.dat|reusableobject|\.ind|\.xls|\.rsrc|\.db|
\.jt|\.psd|\.html|\.lib|\.eps|\.tif|\.nct|\.h/i);
next unless (/\.$extention/i);
chomp;
$myfile = $_ ;
#($myfile) = $_ =~ m!.*\\(.*?\.$extention)!;
#print STDOUT "LINE=$_,extention=$extention,myfile=$myfile=\n";
if ($extention eq "ps") {
next if ($myfile =~ /\+|Variable Information/ || $myfile !~ /\.(ps|sep)$/i);
} elsif ($extention =~ /vps/i) {
next if ($myfile =~ /\+|ABTL/ || $myfile !~ /\.vps$/i);
} elsif ($extention =~ /ppml/i) {
next if ($myfile !~ /\.ppml$/i);
} elsif ($extention =~ /vdx/i) {
next if ($myfile !~ /\.vdx$/i);
} elsif ($extention =~ /pdf/i) {
next if ($myfile !~ /\.pdf$/i);
} elsif ($extention =~ /cjf/i) {
next if ($myfile !~ /\.cjf$/i);
} elsif ($extention =~ /afp/i) {
next if ($myfile !~ /\.afp$/i);
}
#print STDOUT "HERE1\n";
$filename = $myfile;
$filename =~ m!.*\\(.*\.(ps|sep|PS|vps|VPS|PPML|ppml|vdx|VDX|cjf|CJF|afp|AFP))!;
$filename = $1;
#print STDOUT "filename=$filename=\n";
if ($inventory) {
for my $key (keys %$INV) {
#print STDOUT "key=$key\n";
if ($filename eq "$key") {
#print STDOUT "filename=$filename,key=$key\n";
print STDOUT "----\"$filename\" already exists in our DB ...\n";#skip existing files
next;
}
}
}
#sleep 10;

next if ($myfile =~ /vote200/);
print STDOUT "\nnow in file $myfile\n";

#print STDOUT "HERE1\n";
$filenameShort = $myfile; #check if file was processed already
$filenameShort =~ m!.*\\(.*)!;
$filenameShort = $1;
if ( $lookup->{$filenameShort} && $skip) {
#print STDOUT "\n~~~~~~$filenameShort was already processed !!!\n";
} else {
if ($extention eq "ps") {
&threadMe('processPS',$myfile,3600); #timeout=10 minutes
} elsif ($extention =~ /vps/i) {
&threadMe('processVPS',$myfile,3600);
} elsif ($extention =~ /ppml/i) {
&threadMe('processPPML',$myfile,3600);
} elsif ($extention =~ /vdx/i) {
&threadMe('processVDX',$myfile,3600);
} elsif ($extention =~ /pdf/i) {
&threadMe('processPDF',$myfile,3600); #timeout 1 minute
} elsif ($extention =~ /cjf/i) {
&threadMe('processCJF',$myfile,3600); #timeout 1 minute
} elsif ($extention =~ /afp/i) {
&threadMe('processAFP',$myfile,3600); #timeout 1 minute
}
$lookup->{$filenameShort} ="1";
}
#print STDOUT "HERE2\n";
}

select STDOUT;
print "HERE1\n";
close FILE5 || warn "$!\n";
print "HERE3\n";
close LOG || warn "$!\n";
#print STDOUT "HERE3\n";
}



Long live king Moshiach !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top