This project has moved and is read-only. For the latest updates, please go here.

mc_com.exe - success code for scripting purposes.

Jul 13, 2013 at 6:44 PM
Hi there - I am currently writing a batch script to check for updates when a computer is turned on and when it completes the MC updates, loads a different advanced xml document if the updates conditionally found something new or not.

quick info about my setup
I have XBMC running on a server. the clients don't run updates at all. this script would be on the server running mysql etc. I only want xbmc to load on the server if updates are required.

with that in mind, I would love to do something like this:
@ECHO OFF
echo.
echo.
echo Scheduled Startup Script Started!
echo Script created by Kyle Morley
echo.
echo.
    :StartScript
echo Moving to Media Companion Directory...
        C:
        cd "C:\Media Companion\"
        TIMEOUT /t 2 >NUL
echo.
echo.
    :MCUpdates
        echo - Media Companion will now check for new content.
            TIMEOUT /t 2 >NUL
echo.
echo.
    :Movies
        echo - Checking for new Movies...
            TIMEOUT /t 2 >NUL
            mc_com.exe -m >NUL
        echo - - Complete!
            TIMEOUT /t 2 >NUL
echo.
echo.
    :TVShows
        echo - Checking for new TV Shows...
            TIMEOUT /t 2 >NUL
            mc_com.exe -e >NUL
        echo - - Complete!
            TIMEOUT /t 2 >NUL
echo.
echo.
    :MCUpdates
        echo - Update Check Complete!
            TIMEOUT /t 2 >NUL
echo.
echo.
echo.
echo.
    :TheQuestion
        TIMEOUT /t 2 >NUL
            IF EXIST "success.txt" (GOTO UpdatesRequried) ELSE (GOTO NoUpdatesRequired)
    :UpdatesRequired
        echo - XBMC will loaded to process new udpates...
            xcopy "success\advancedsettings.xml" "C:\Users\Kyle\AppData\Roaming\XBMC\userdata\"
            cd "C:\Program Files (x86)\XBMC"
            start xbmc.exe
            GOTO ExitScript
    :NoUpdatesRequired
        echo - No new updates required!
        echo - XBMC will not be loaded.
            TIMEOUT /t 2 >NUL
            GOTO ExitScript
echo.
echo.
    :ExitScript
        echo Exiting...
            TIMEOUT /t 5 >NUL
            Exit
as you can see from the script - the idea is to check for updates within Media companion command line. then check if xbmc is needed to load at all, and only load it if updates are required. this would make my setup really fluid for my server.

Currently, my server periodically loads xbmc to do this - but I would like it to only load when necessary.

but there isn't really an option to do 'success' bit. There is the option in the mc_com to write the results to a text file - but I can't use the script to rely on that alone. The output would still output regardless of updates or not.
I was wondering if this functionality could be extended to whether or not MC_COM finds updates... Is this possible?

Another way might be to check the errorlevel of the results - but I still don't think that would work because the cmd is still executed regardless of updates or not.

any thoughts?
Jul 13, 2013 at 8:33 PM
This may be possible.

I was going to look at some sort of exit code for mc_com, but didn't have a chance yet.

I could add a switch for writing a success.txt file, say '-s' so you could code it as mc_com.exe -m -s
but you would have to do movies and TV together,

mc_com.exe -m -e -s

Reason being is mc_com would need to delete the 'success.txt; file when it starts, so if it isn't successful, no 'success.txt' file would exist.

May have to look into exit codes instead, but will add to the To Do List as a feature.
Jul 13, 2013 at 9:47 PM
Thanks vbat for the quick response!

as a hypothetical:
If I could do mc_com.exe -m -s (to keep it singular) then I could check;
if success.txt exists, create update.txt
then
mc_com.exe -e -s,
even if success.txt is deleted for this instance, the update.txt would remain and i could check if either part was successful.
then delete the update.txt at the end of script - It's messy, but would work i guess.

If mc_com.exe -m -e -s could produce a success.txt file similar to the "brief" output log based on the main program (assuming it found new content), then that would be really versatile and useful addition to the cmd line.

equally, exit codes would be great. I assume I could just check for a specific code relating to a function of the cmd line, similar to checking an errorlevel of an in-built cmd?

Thanks again,
Kyle.
Jul 13, 2013 at 9:54 PM
Suppose having -s to output with either and both -m , -e would work.

As for exit codes. still very new to this, so need to research.
Jul 14, 2013 at 2:07 AM
Hmm, Exit codes are relatively simple... But i forgot how to do them aswell, It's been a while. This feature would be great though :)
Jul 15, 2013 at 12:06 AM
@shadeblack - Done.

next release with have mc_com.exe exit with ERRORLEVEL codes:

ErrorLevel = 0 - Nothing scraped
ErrorLevel = 1 - Error
ErrorLevel = 2 - Movie(s) Scraped
ErrorLevel = 4 - Episode(s) Scraped
ErrorLevel = 6 - Movie(s) and Episode(s) scraped (using -m & -e)

Check with "IF ERRORLEVEL > 1 goto updaterequire"
Jul 15, 2013 at 2:15 AM
Awesome vbat!

Amazed this was done so quickly. Thanks so much! This'll make things really smooth :)

Thanks to the whole team here at MC too!
Jul 16, 2013 at 6:17 PM
Hi guys, I tested out the new cmd line with the latest version with this:
@ECHO OFF
echo.
echo.
    :MCStart
        echo - Media Companion will now check for new content.
        echo - - This may take some time!
            C:
            cd "C:\Media Companion\"
            mc_com.exe -m -e >NUL
        echo - Update Check Complete!
            TIMEOUT /t 1 >NUL
            IF ERRORLEVEL 6 echo - errorlevel 6
            IF ERRORLEVEL 4 echo - errorlevel 4
            IF ERRORLEVEL 2 echo - errorlevel 2
            IF ERRORLEVEL 1 echo - errorlevel 1
            IF ERRORLEVEL 0 echo - errorlevel 0
But code 0 returns even when MC-COM finds new content.
have I done something wrong, or would this be an issue with the latest release?

Thanks again,
Kyle.,
Jul 16, 2013 at 9:59 PM
Edited Jul 16, 2013 at 10:00 PM
Well, your outputting to NUL, which means no errorlevel code is passing on, so ERRORLEVEL is set to 0 by the system.

Just tested your code but modified, and it outputs
errorlevel 4
errorlevel 2
errorlevel 1
errorlevel 0

So tested as this:
@ECHO OFF
echo.
echo.
    :MCStart
        echo - Media Companion will now check for new content.
        echo - - This may take some time!
            E:
            cd "MC\MC 3.573b"
            mc_com.exe -m -e 
        
echo %ERRORLEVEL%
            IF ERRORLEVEL = 6 GOto e6
            IF ERRORLEVEL = 4 GOto e4
            IF ERRORLEVEL = 2 GOto e2
            IF ERRORLEVEL = 1 GOto e1
            IF ERRORLEVEL = 0 GOto e0

:e6
echo - errorlevel 6
goto END

:e4
echo - errorlevel 4
goto END

:e2
echo - errorlevel 2
goto END

:e1
echo - errorlevel 1

:e0
echo - errorlevel 0


:END
Pause
And I'm getting errorlevel 4, when no movies.

Seems it works, but I've put a catch for movies in the wrong place, so will have to fix that.
Jul 16, 2013 at 10:50 PM
Edited Feb 26, 2015 at 2:52 AM
Sorry about that, bit I've fixed it.

Above program (code I show in last post) does work correctly.
ErrorLevel is 2 if only a Movie is found
ErrorLevel is 4 if only a Episode is found
&
ErrorLevel is 6 if both a movie and eoisode is found.

Cheers
Jul 16, 2013 at 11:44 PM
vbat99 wrote:
Well, your outputting to NUL, which means no errorlevel code is passing on, so ERRORLEVEL is set to 0 by the system.
Wow didn't even notice this.
I have a habit of NUL'ing everything :P
thanks again for everything!