|
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. |
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
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. |
#3
|
|||
|
|||
Thanks Andy... Will try this and report back.
|
#4
|
||||
|
||||
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) 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. |
#5
|
|||
|
|||
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 |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|