Shea, Linchi said:
> I had to do the following, for instance, to find the
> full path for SQL utility osql.exe:
>
> [code removed]
>
> Is there a simpler way? [...] This is simply too ugly.
>

If you're into compressed code, the whole thing can be
made into a one-liner:

  ($app) = grep -f, map "$_\\osql.exe", split ';', $ENV{PATH};

Of course, this is even uglier than the original.  :)

This isn't any shorter, but it's a little simpler:

  for my $path (split ';', $ENV{PATH})
    {
      if (-e "$path\\osql.exe")
        {
          $app = "$path\\osql.exe";
          last;
        }
    }

Both examples use the $ENV{PATH} instead of `path`.  It's faster,
and you don't have to strip off the "PATH=" at the beginning.

Also, both leave $app undefined if osql.exe isn't found in the
path.  This allows you to test $app before attempting to launch
the process.

--Bill




-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of
Shea, Linchi
Sent: Thursday, March 15, 2001 4:45 PM
To: Perl-Win32-Admin@Listserv. Activestate. Com (E-mail)
Subject: Path of an EXE file


To use Win32::Process::Create, one must supply the full path of the program
to be launched. It's obviously not good to hard code the path if that
program may be installed in different directories on different machines. I
had to do the following, for instance, to find the full path for SQL utility
osql.exe:

my @path = grep(/sql/i, split(/;/, `path`));
my $app;
foreach my $path (@path) {
    $app =  "$path\\osql.exe";
    last if (-f "\"$app\"");
}
Win32::Process::Create($process, $app, $osql, 1,
$Win32::Process::CREATE_NEW_PROCESS, ".");
...

If the directory happens to be the first on the path, one also has to stripe
off 'PATH='.

Is there a simpler way? There gotta be a simpler way. This is simply too
ugly.

Linchi

_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-admin

_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-admin

Reply via email to