SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV Studio
Forum Rules FAQs Community Downloads Today's Posts Search

Notices

SageTV Studio Discussion related to the SageTV Studio application produced by SageTV. Questions, issues, problems, suggestions, etc. relating to the Studio software application should be posted here.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 11-22-2005, 06:16 PM
infiniti_guy infiniti_guy is offline
Sage Advanced User
 
Join Date: Sep 2004
Posts: 116
Executable Error Code Return

Is there a way to launch an executable via "ExecuteProcess" command and receive an error code for the executable into Sage/Studio?

For example, I have an executable that returns 0 for success and 1 for error, and I want to read that error code via a return from the execute process command to know if my process was successful.

I know there are some other ways to do this with files and parsing, but they are much less elegant. Can I get the error code directly from the executable easily with Studio?

Thanks
Reply With Quote
  #2  
Old 11-22-2005, 06:24 PM
Opus4's Avatar
Opus4 Opus4 is offline
Administrator
 
Join Date: Sep 2003
Location: NJ
Posts: 19,624
While I haven't used this... the API docs for ExecuteProcess() say that it returns "the java.lang.Process object that represents the launched process". So, perhaps you could then use the exitValue() method from java.lang.Process?

- Andy
__________________
SageTV Open Source v9 is available.
- Read the SageTV FAQ. Older PDF User's Guides mostly still apply: SageTV V7.0 & SageTV Studio v7.1.
- Hauppauge remote help: 1) Basics/Extending it 2) Replace it 3) Use it w/o needing focus
- HD Extenders: A) FAQs B) URC MX-700 remote setup
Note: This is a users' forum; see the Rules. For official tech support fill out a Support Request.
Reply With Quote
  #3  
Old 11-22-2005, 06:30 PM
infiniti_guy infiniti_guy is offline
Sage Advanced User
 
Join Date: Sep 2004
Posts: 116
Thanks Andy... Will try this and report back.
Reply With Quote
  #4  
Old 11-23-2005, 03:09 AM
nielm's Avatar
nielm nielm is offline
SageTVaholic
 
Join Date: Oct 2003
Location: Belgium
Posts: 4,496
Note that ExecuteProcess will run the process in the background, so you need to first wait for the process to exit first using: java_lang_Process_waitFor(p), otherwise you will get a IllegalThreadStateException...
This will block the Sage UI unless you run it in a separate thread, so you need to Fork()...

Code:
-> p=ExecuteProcess("my.exe", "args",null,true)
    +-> IF p != null
        +-> Fork()
            +-> java_lang_Process_waitFor(p)
                +-> ExitVal=java_lang_Process_exitValue(p)
As an example, look at the code for running Comskip in Malore's STV -- he executes a process, forks a thread, waits for the process, then reads the result...

One other warning... For ExecuteProcess, setting the last arg to true discards the output of the process, which is normally what you want to happen.

If you actually want to read and use the output of the process in Sage, set it last arg to false, but you MUST read both the stdout and stderr of the process (usually in 2 separate threads) otherwise the process will block on output and run forever.

More help with Java Process execution can be found in this Java World article.
__________________
Check out my enhancements for Sage in the Sage Customisations and Sageplugins Wiki

Last edited by nielm; 11-23-2005 at 04:42 AM.
Reply With Quote
  #5  
Old 11-23-2005, 03:25 PM
infiniti_guy infiniti_guy is offline
Sage Advanced User
 
Join Date: Sep 2004
Posts: 116
Niel,

That did the trick. I didn't have the IF or Wait in my test code and I got the errors you mentioned. Now its returning the values properly, and I'm not using the console returns, so discarding them works just fine

Thanks
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 06:10 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.