check process

Hi there,

how can i start a process in xojo and overwatch it all time if it is up?

Greetings :slight_smile:

[quote=282003:@Sascha Mierke]Hi there,

how can i start a process in xojo and overwatch it all time if it is up?

Greetings :)[/quote]
Are you referring to starting a linux / OS X process from Xojo?

Could you be more specific ? Which kind of process ? Under which system ? Mac, Windows, Linux ? Is it an external program ? Do you want to launch it as a service or as a regular program ?

Make it a service application and set it to restart automatically.

The APP should start a programm on Windows for example … and then i have to know all time if the process is up or shutdown

Sascha,

On OS X/Linux I would launch the program with a shell. Then I check on it with a timer (ps -aef | grep app) for example to see if it is up or not.

Is this something like you mean?

On Windows, you can get the list of running processes by shelling to Tasklist.

So what you do is launch your process, and monitor it regularly, for instance with a timer, with TaskList.

MBS Plugin has classes to list processes:

http://www.monkeybreadsoftware.net/class-linuxprocessmbs.shtml
and
http://www.monkeybreadsoftware.net/class-processmbs.shtml

On Mac you can get notifications via CarbonApplicationEventsMBS or NSWorkSpaceMBS about apps quitting or launching.

[quote=282283:@Mike Cotrone]Sascha,

On OS X/Linux I would launch the program with a shell. Then I check on it with a timer (ps -aef | grep app) for example to see if it is up or not.

Is this something like you mean?[/quote]

Yes this is the procedure i do that with visual studio… but it seems that xojo cant this things by it self.

I dont want to buy so many plugins for all this standard features, Xojo is expensive enough :wink:
So it seems i have to troll around with tasklist :confused:

[quote=282400:@Sascha Mierke]Yes this is the procedure i do that with visual studio… but it seems that xojo cant this things by it self.

I dont want to buy so many plugins for all this standard features, Xojo is expensive enough :wink:
So it seems i have to troll around with tasklist :/[/quote]

You don’t have to buy any plugins for accomplishing your goals as I understand it. Not sure what you mean about trolling around w/ a tasklist since your goals should not be too many lines of code.

Launching a shell is built into Xojo…

Normally i do it like this

Private Shared Sub startJD() jdp.Start() 'prozess check If jdp.HasExited = False Then end if End If

Does Xojo know the PID when it starts a process?

What about this in Xojo?

[code]If sh.IsRunning then

end if[/code]

This should check if the process is running i think?

On Windows, the shell process is not a child of the main process like it would be in LInux or on Mac. As a consequence, the shell may terminate before the launched process has ended.

Oh well…

See https://forum.xojo.com/6243-force-quit-a-shell-windows/20 for a declare to get the PID.

hmmm so why isnt this working?

Dim sh As New Shell sh.Arguments = "-Djava.awt.headless=true -jar C:\\Users\\Sascha\\AppData\\Local\\JDownloader 2.0\\JDownloader.jar" sh.Execute("C:\\Users\\Sascha\\AppData\\Local\\JDownloader 2.0\\jre\\bin\\javaw.exe")

on vs there is no problem with this, but Xojo seems to be have a problem with this arguments, cause it just launches jawaw

Can you use (for Windows) “wmic process call create”, get the ProcessID, and monitor it via timer until the ProcessID is no longer?

Example of how to get processID from application started from shell (reference post):

wmic process call create "notepad.exe" | find "ProcessId"

[quote=282738:@Sascha Mierke]hmmm so why isnt this working?

Dim sh As New Shell sh.Arguments = "-Djava.awt.headless=true -jar C:\\Users\\Sascha\\AppData\\Local\\JDownloader 2.0\\JDownloader.jar" sh.Execute("C:\\Users\\Sascha\\AppData\\Local\\JDownloader 2.0\\jre\\bin\\javaw.exe")

on vs there is no problem with this, but Xojo seems to be have a problem with this arguments, cause it just launches jawaw[/quote]

Arguments are arguments to how the SHELL is started - not to the process you’re trying to run using execute

Execute also has an optional “parameters” argument - see http://documentation.xojo.com/index.php/Shell.Execute
Try
sh.Execute(“C:\Users\Sascha\AppData\Local\JDownloader 2.0\jre\bin\javaw.exe”, “-Djava.awt.headless=true -jar C:\Users\Sascha\AppData\Local\JDownloader 2.0\JDownloader.jar” )

@Norman Palardy

Oh that is the magic, thank you :slight_smile: the run seems to work but the path is a problem, i think i have to use the path with “” but how xojo workt with this in strings…

sh.Execute("C:\\Users\\Sascha\\AppData\\Local\\JDownloader 2.0\\jre\\bin\\javaw.exe", """-Djava.awt.headless=true -jar C:\\Users\\Sascha\\AppData\\Local\\JDownloader 2.0\\JDownloader.jar""")

In VS i coded it like this:

jdp.StartInfo.FileName = jdPath & "jre/bin/javaw.exe" jdp.StartInfo.Arguments = "-Djava.awt.headless=true -jar """ & jdPath & "JDownloader.jar""" jdp.StartInfo.UseShellExecute = False jdp.StartInfo.RedirectStandardOutput = False jdp.StartInfo.CreateNoWindow = False jdp.StartInfo.WorkingDirectory = jdPath

with a cmd you start it like this:

javaw.exe -Djava.awt.headless=true -jar “C:\Users\Sascha\AppData\Local\JDownloader 2.0\JDownloader.jar”
pause

Double the double quote.

myString = ""this is a quoted string ""

This is a syntax error for Xojo ;(

path = ""C:\\Users\\Sascha\\AppData\\Local\\JDownloader 2.0\\JDownloader.jar""

tried it like this:

[code] Dim sh As New Shell
Dim path as string = “”“C:\Users\Sascha\AppData\Local\JDownloader 2.0\JDownloader.jar”""
Dim arg as string = "-Djava.awt.headless=true -jar " + path

System.DebugLog(arg)
sh.Execute(“C:\Users\Sascha\AppData\Local\JDownloader 2.0\jre\bin\javaw.exe”, path)[/code]

but it seems that Xojo has problem with this long path names, i got this message now:

and here i see the path is wrong :frowning: