Re: [Gambas-user] Check if a program is already started

2009-09-13 Thread Jussi Lahtinen
Your code is fine for checking if some program is running, but it
cannot check double instance.
If your program asks pid of itself, it will find it!
I didn't know about pidof (I have used Linux about one year), so thanks!

Jussi

PS.
You don't need variable running, you can just do Return False or
Return True.
Also try is unneeded.



On Sat, Sep 12, 2009 at 17:20, Jesus Guardon jguar...@telefonica.net wrote:
 Just another way:

 PUBLIC FUNCTION pidOf(program AS String) AS Boolean
     'checks if a program is running
     DIM gotpid AS String = 
     DIM running AS Boolean = FALSE
     TRY SHELL pidof   program TO gotpid
     IF gotpid THEN
         running = TRUE
     ELSE
         running = FALSE
     ENDIF
     RETURN running
 END

 Usage:

 IF pidOf(yourProgram) THEN whatever...

 At least it works for me

 Cheers

 Jesus

 Jussi Lahtinen escribió:
 Not very elegant, but works:


 Dim sOutput As String

 Exec [pgrep, -f, -l, NameOfYourProgram.gambas] Wait To sOutput

 If Split(Trim$(sOutput), gb.NewLine).Count  1 Then
 'Allready running
 EndIf


 Jussi

 --
 Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
 trial. Simplify your report design, integration and deployment - and focus on
 what you do best, core application coding. Discover what's new with
 Crystal Reports now.  http://p.sf.net/sfu/bobj-july
 ___
 Gambas-user mailing list
 Gambas-user@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/gambas-user


--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Check if a program is already started

2009-09-13 Thread Jesus Guardon
Jussi Lahtinen escribió:

 You don't need variable running, you can just do Return False or
 Return True.
 Also try is unneeded.

You are right!
And for the subject of the thread, next time I will read carefully.

Sorry!

Jesus

--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Check if a program is already started

2009-09-12 Thread Jussi Lahtinen
Not very elegant, but works:


Dim sOutput As String

Exec [pgrep, -f, -l, NameOfYourProgram.gambas] Wait To sOutput

If Split(Trim$(sOutput), gb.NewLine).Count  1 Then
'Allready running
EndIf


Jussi




On Sat, Sep 12, 2009 at 15:50, Johny Provoost johny.provo...@skynet.be wrote:
 Hi,

 Is there a command to check if a program (programed in Gambas) is
 already running?
 I want to avoid that a program is started twice.


 Johny Provoost


 --
 Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
 trial. Simplify your report design, integration and deployment - and focus on
 what you do best, core application coding. Discover what's new with
 Crystal Reports now.  http://p.sf.net/sfu/bobj-july
 ___
 Gambas-user mailing list
 Gambas-user@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/gambas-user


--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Check if a program is already started

2009-09-12 Thread Jesus Guardon
Just another way:

PUBLIC FUNCTION pidOf(program AS String) AS Boolean
 'checks if a program is running
 DIM gotpid AS String = 
 DIM running AS Boolean = FALSE
 TRY SHELL pidof   program TO gotpid
 IF gotpid THEN
 running = TRUE
 ELSE
 running = FALSE
 ENDIF
 RETURN running
END

Usage:

IF pidOf(yourProgram) THEN whatever...

At least it works for me

Cheers

Jesus

Jussi Lahtinen escribió:
 Not very elegant, but works:
 
 
 Dim sOutput As String
 
 Exec [pgrep, -f, -l, NameOfYourProgram.gambas] Wait To sOutput
 
 If Split(Trim$(sOutput), gb.NewLine).Count  1 Then
 'Allready running
 EndIf
 
 
 Jussi

--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user