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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding PID for print process in perl script on Win NT???

Status
Not open for further replies.

Jimbo2112

IS-IT--Management
Mar 18, 2002
109
GB
Hi All,

I have a script that works in Win NT and fires up Acrobat to print pdf's from a list and then move them to another place. What I need to do is catch the PID of the print function that Acrobat uses so I can check when the printing has finished before trying to move the file.

I have seen some modules that look like they might deal with this, but my Perl is basic and I need to be guided to the most suitable for this task. Also a lot of the solutions are for Perl under a Unix OS which is no use to me! (Although Unix is far superior, but that's another story!)

Any ideas?

Cheers

Jimbo
 
Jimbo,

can you post the print section of the script

$$ is the PID for the current process, but if we see the print statement we might be able to see what's going on.

If you're shelling a command script to print, add the move command to the shell script as well, you wont need the PID at all

HTH
--Paul
 
Paul,

The sub for the script in question is below. The part that I am interested in is before and after the unlink statement. I need to capture the PID that the system command creates and check for the existence of that PID. When it no longer exists I want to do the unlink on the file being printed.

Sorry for being simplistic, but I am not an expert in Perl!

Cheers

Jimbo

#Set up variables
$mono = "\\\\srv-xpp\\shared\\ftp_print\\mono" ;
$mono_done = "\\\\srv-xpp\\shared\\ftp_print\\mono\\done" ;
$reader = '"C:\\Program Files\\Adobe\\Acrobat 4.0\\Acrobat\\Acrobat.exe"';
@options = ('/p', '/h' );
$list_mono = `dir $mono`;
@args = ($reader, @options);

#---------------------------------------------------------------------#
sub MONO
{
$list_mono =~ /File\(s\)[ ]+([0-9,]+)/ ;
$size1 = "$1";
print LOG "$size1 \n";

sleep 1;

($list_mono, @full_list) = `dir $mono`;
$list_mono =~ /File\(s\)\s+([0-9,]+)/ ;
$size2 = "$1";

print LOG @full_list;
print LOG "$size2 \n";
if ($size1 eq $size2)
{
foreach (@full_list)
{
if (s/^.*?([\w]+.pdf)$/$1/)
{
system ( @args, $mono."/".$_ );
chomp;
copy ($mono."/".$_ ,"$mono_done");
unlink ($mono."/".$_);
}
}
}
}
 
Why not use rename instead of copy as the directories appear to be on the same path. Moving the files would be a lot quicker, as it wouldn't have to copy the file, just change the table info from one directory to another.

Getting the PID could be achieved by shelling a ps command, but system forks and waits for a response, and it should be inline in that the rename command could only proceed after the system command has completed. At least that what isays in the book - don't have your config so can't test

another poss
Code:
RENAME_FILE:
  rename "file1", "done/file1" or goto RENAME_FILE;

Haven't tested this, but it should rename the file to the done directory below it, or else try agin until success


HTH
--Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top