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

Taking Extra Time to create STDOUT

Status
Not open for further replies.

nitindn

Programmer
Feb 18, 2003
6
AU
Hi,
I am using the Perl 5.8.0 (Build 804) on Windows 2000 OS...I am facing a very weird problem..

I am using the Win32::process::Create for creating a process to extract the Jar information from a file using jar.exe which is kept in the JAVA_HOME\bin directory..
The code used to do is something like this:

open STDERR, ">error" ;
open STDOUT, ">extrackpkgname";
$appname = "$_MCenv_JAVA_HOME\\bin\\jar.exe";
$cmdline = "jar -tf $_MC_datajar";
$curdir = ".";
&startChildProcess("$appname","$cmdline","$curdir");
open (_MCifh_pkgname , &quot;<extrackpkgname&quot;);
if ( -s &quot;extrackpkgname&quot; )
{
@_MCavar_pkgname = <_MCifh_pkgname>;
close _MCifh_pkgname;
chomp(@_MCavar_pkgname);
}
else
{
$_MCsvar_Error_Message = &quot;Failed To Extract Package Information Of the jar '$_MC_datajar' &quot;;
PrintErrLog( &quot;$_MCsvar_Error_Message&quot; );
returnToIF( &quot;$_MCsvar_Process_Desc&quot;, &quot;1&quot;, &quot;$_MCdir_ErrorLogDir&quot; );
}
foreach(....)

sub startChildProcess
{
my ($appname,$cmdline,$curdir) = @_;
my $process_obj;
Win32::process::Create($process_obj,$appname,$cmdline,1,NORMAL_PRIORITY_CLASS,$curdir);
$Pid = $process_obj->GetProcessID();
open( _MCifh_ , &quot;>>$ENV{CLIENTDIR}\\appdata\\tmp\\processids.txt&quot; );
if ( ! flock( _MCifh_ , 2|4))
{
$Error_Message = &quot;Performing User Initiated Cancel Action&quot;;
PrintErrLog( &quot;$Error_Message&quot; );
returnToIF( &quot;$Process_Desc&quot;, &quot;1&quot;, &quot;$ErrorLogDir&quot; );
}
print _MCifh_ &quot;$Pid\n&quot; ;
close _MCifh_ ;
$process_obj->Wait(INFINITE);
}

Now what happens here is that the STDOUT file takes around 10-15 seconds to be created and by that time my control comes out of the
if ( -s &quot;extrackpkgname&quot; ) , without even detecting the existence of more than 0 KB file as a result of which my script fails.(i.e the control comes into the else part of if ( -s &quot;extrackpkgname&quot; ) as by that time that file has not been created, though after 10-15 the file gets created).The same script runs fine on other machine having the same OS and on my machine the problem creeps up everytime.

Can you suggest me the reason for the same and some corrective actions as well..
A fast response would highly be appreciated...
 
Create a tempoprary file at the start of your process, and delete it when complete.

Put a while loop to determine the existence of the file, when the test fails (cause your process has exited) exit the while loop and proceed

HTH
--Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top