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!

Simple execute and exit

Status
Not open for further replies.
May 3, 2003
90
CA
Hello all,

I wrote a little script and im having some trouble. It looks for a process and executes the exe if the process is not running. I cant seem to get the execute and exit part.

#!Perl -U

use strict;
use warnings;
use Win32::perfLib;
use File::Find;

my $server;
my $proc_ref = {};
my %counter;
my @FileList;

Win32::perfLib::GetCounterNames($server, \%counter);

my %r_counter = map { $counter{$_} => $_ } keys %counter;

my $obj = $r_counter{Process};
my $id = $r_counter{'ID Process'};

my $perf = new Win32::perfLib($server);
$perf -> GetObjectList($obj, $proc_ref);
$perf -> Close();

my $inst_ref = $proc_ref -> {Objects} -> {$obj} -> {Instances};

foreach my $pr (keys %{$inst_ref}) {

my $counter_ref = $inst_ref -> {$pr} -> {Counters};

foreach my $inf (keys %{$counter_ref}) {

if ($counter_ref -> {$inf} -> {CounterNameTitleIndex} == $id) {

if ($inst_ref -> {$pr} -> {Name} =~/fsremote/i) { exit; }
else { &exec_proc; }

}

}

}

sub exec_proc {

my $drv = 'c:/program files';

find(\&do_it, $drv);

foreach (@FileList) {
if (/fsremote.exe/i) {

# part where i would like to execute the exe and exit sctipt.

}
}

}

sub do_it {

my $name = $File::Find::name;
$FileList[++$#FileList] = $name;

}

Any help is greatly appreciated
 
system("C:/Program Files/fsremote.exe");

??
Paul
 
Code:
sub exec_proc
{
	if (-e "c:\\program files")
	{
		find( sub { push my @foundfiles, $File::Find::name if /fsremote.exe/i }, "c:\\program files" );

		do
		{
			# 404! do something?
			exit;
		} unless $foundfiles[0];
		
		system($foundfiles[0]);
	}
}

this should do ..



---------------------------------------
bah
 
I need to explain a little more.
The exe is an application that runs 24/7. if i use system or exec , the perl script never exits until the exe terminates (which neveer does). I need something that will execute the exe , exit the perl script and leave the exe running. I have tried loading it as a process but its not the same as executing the file.

I hope this is a little more clear
 
TheGenius22,
Have you tried calling system like such:
Code:
system(1,"fsremote.exe");
The initial one should make windows spawn the system call as an async process. You might also be able to preced your command with 'start /b'. eg:
Code:
system("start /b fsremote.exe");
Since I don't do windoze these are just ideas based on half remebered windoze stuff.

Hope one of these helps.
 
thanks usige

the system(1, "command") works like a charm.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top