Detecting Exitcode of an external process

If you have a question or need help, this is the place to be.
Post Reply
nkapur
Posts: 8
Joined: Fri Jan 30, 2009 1:42 am

Detecting Exitcode of an external process

Post by nkapur » Tue Aug 11, 2009 1:31 am

I need to execute a process and inspect the exitcode of the process. Is there a way to do that using System Execute action? Alternately, can a python command/script be written to do this using spawn... commands? (I tried to call os.spawnlp but get a error: module object has no attribute spawnlp). I'm not a Python programmer :(

User avatar
jinxdone
Plugin Developer
Posts: 443
Joined: Tue Jan 02, 2007 4:08 pm

Re: Detecting Exitcode of an external process

Post by jinxdone » Tue Aug 11, 2009 7:06 am

One simple way to do it is to use a batch file like this one to launch the app:

Code: Select all

myapp.exe
"C:\Program Files\EventGhost\EventGhost.exe" -e errorlevel %ERRORLEVEL%
So, after the program finishes trigger an action with the %ERRORLEVEL% in the eg.event.payload variable. Or you could put the errorlevel as the name of the action if you prefer it that way.

I think it should be also possible to do it with a script, but I've never tried it. The python docs probably come in handy if you want to look into it.
http://docs.python.org/library/subprocess.html
http://docs.python.org/library/os.html

-jinxdone

User avatar
Bitmonster
Site Admin
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Re: Detecting Exitcode of an external process

Post by Bitmonster » Tue Aug 11, 2009 12:09 pm

System.Execute in 0.3.7.r1170 returns the exit code as eg.result if "wait for completion" is checked.
Please post software-related questions in the forum - PMs will only be answered, if really private, thanks!

User avatar
jinxdone
Plugin Developer
Posts: 443
Joined: Tue Jan 02, 2007 4:08 pm

Re: Detecting Exitcode of an external process

Post by jinxdone » Tue Aug 11, 2009 4:38 pm

Since Bitmonster added this into EG properly everybody should disregard my previous post. Thanks again Bitmonster!

-jinxdone

nkapur
Posts: 8
Joined: Fri Jan 30, 2009 1:42 am

Re: Detecting Exitcode of an external process

Post by nkapur » Thu Aug 13, 2009 6:44 pm

Bitmonster, thanks for the new version. Works like a charm :)

jinxdone, thanks for the info. I did look at the Python docs which is where I got the syntax for spawn... etc. General question though - can any python command be called (after importing relevant module) or are there some security restrictions?

User avatar
jinxdone
Plugin Developer
Posts: 443
Joined: Tue Jan 02, 2007 4:08 pm

Re: Detecting Exitcode of an external process

Post by jinxdone » Fri Aug 14, 2009 7:52 am

There should be no restrictions. Some things are already implemented in EG though, so you don't have to create everything from scratch. Check out the "help -> python shell", it can be quite useful.

If you have experience in programming with some other language just read the python tutorial and you can probably get started with scripts in EG without problems.

Oh, and welcome! :)

-jinxdone

stottle
Plugin Developer
Posts: 636
Joined: Sun Apr 26, 2009 10:59 pm

Re: Detecting Exitcode of an external process

Post by stottle » Fri Aug 14, 2009 1:12 pm

jinxdone wrote:
nkapur wrote: or are there some security restrictions?
There should be no restrictions.
???

If that were true, we wouldn't have problems with the Mce Remote on Vista and Win7, right? Unless you run EG as admin or with UAC off, you won't be able to do things you "normally" wouldn't be able to do, such as change system files. Sorry to jump in at the end here, but I've been working on an alternate Mce Remote capability, so I thought this was worth mentioning.

Brett

User avatar
jinxdone
Plugin Developer
Posts: 443
Joined: Tue Jan 02, 2007 4:08 pm

Re: Detecting Exitcode of an external process

Post by jinxdone » Fri Aug 14, 2009 3:05 pm

Well, thats a feature of Vista/Win7 and not really a restriction in EG. As far as I know the same happens for any other program you run on Vista/Win7 that tries to work with drivers or write system files.

Post Reply