[Gambas-user] Avoiding multiple instances

Benoit Minisini gambas at ...1...
Fri Feb 1 13:31:52 CET 2008


On vendredi 1 février 2008, Stefano Palmeri wrote:
> Alle 18:38, giovedì 31 gennaio 2008, Epíleg ha scritto:
> > En/na Stefano Palmeri ha escrit:
> > > Alle 16:45, giovedì 31 gennaio 2008, Stefano Palmeri ha scritto:
> > >> I use this simple code:
> > >>
> > >> PUBLIC SUB Main()
> > >>
> > >>   DIM sShellOutput AS String
> > >>
> > >>   SHELL "ps aux | grep " & Application.Name & ".gambas" & " | grep -v
> > >> grep" TO sShellOutput
> > >>
> > >>   IF sShellOutput THEN QUIT
> > >>
> > >> END
> > >
> > > or better:
> > >
> > > PUBLIC SUB Main()
> > >
> > >   DIM sShellOutput AS String
> > >
> > >   SHELL "ps aux | grep " & Application.Name & ".gambas" &
> > >         " | grep -wv grep | wc -l" TO sShellOutput
> > >
> > >   IF Val(sShellOutput) > 1 THEN QUIT
> > >
> > > END
> >
> > Very good solution. Thanks a lot!
> >
> > Epíleg.
>
> I found out that using Application.Args[0] is better,
> because we don't have to care if the user renames the binary.
>
> PUBLIC SUB Main()
>
>    DIM sShellOutput AS String
>
>      SHELL "ps aux | grep  -w " & Application.Args[0]&
>          " | grep -wv grep | wc -l" TO sShellOutput
>
>      IF Val(sShellOutput) > 1 THEN QUIT
>
> END
>
> Stefano
>

I have a 'pgrep' command on my system for finding a process from its name (and 
many other things).

Regards,

-- 
Benoit Minisini




More information about the User mailing list