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

exec question...

Status
Not open for further replies.

crackn101

Programmer
Dec 27, 2002
63
US
Hi Everyone.
I have a perl script that checks for the existance of a window handle, if found then operates on that window.
If not found, then launch the application, then operate on that window.
I suppose the problem is, that if i use exec to launch the
app, my script terminates imediatly, which is no good.
On the other hand if I spawn the app using system,
which i should do, then my script is tied to the app until
the app terminates.
Because the current running state of the app is assumed
to be unknown at the start of the script, if i keep launching the script multiple times, which will be the case,
i take chance of tying up system resources, since it basically is starting multiple instances of the same
script ???
Assuming i don't force the app to close at the end of each
session, then i will end up with at least 2 running instances of the script.
Instance 1 will be the intial system call that started the app,
and Instance 2 will be each session of the script as it
is called again, and sees that the app is still running.
Hope that's not confusing. I've been starring at this
way too long. :)
Anyway here is a little bit of code :
Code:
TOP:
  &LogOpenWindows();
  $login_hwnd = &FindMyWindow("ROCLINK for Windows");
  if($login_hwnd eq '-1') # ie not found
  {    
   if($topcnt > 2) # if attempts to load > 2 abort trying
    {
     print hand "Rocklink is not running !\n";	
     close(hand); 
     exit;
    }
   else
    {
	 system("perl launchfile.pl"); #attempt to load app
	 sleep 2;
	 $flg_NeedToLogin = "YES";	 
	 $topcnt++;
	 goto TOP;
	}	
  }

Here is the code in launchfile.pl

Code:
use Win32::GuiTest;
 open(hand,">c:\\tony_launchfile.txt");
 print hand "Launchfile.pl\n";
 print hand "Checking for rocklink....\n";
 $parent = Win32::GuiTest::FindWindowLike(0, "ROCLINK For Windows","");
 if($parent) 
  { 
    print hand "Roclink already running!\n"; 
    close(hand); 
    exit; 
  } 
 print hand "Launching Rocklink now !\n";
 close(hand);
 system(qw(start C:/"Program Files/ROCLINK for Windows"/Bin/ROCLink.exe));
 exit;
I guess what it boils down to is, i need to launch an
application using perl, without the perl script being tied to the app 'waiting' for the app to terminate.
If i use a script like this :
PARENT script
{
system( CHILD script { system(MyApp.exe); } )
pause for app to load then, get window handle
and move on.
}
That way the child script terminates after the app is called,
but the parent script rolls on, without being tied to the app.
In the child script i used exec, but then the app wouldn't
launch. Using system, it launches every time.
TIA for any suggestions.
 
Check out Win32::process and I'm pretty sure you need to use the DETACHED_PROCESS constant. There's a good example in the documentation
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top