Kodi Community Forum

Full Version: help with bat file that will not launch
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all I am trying to get xbmc to launch an iso on my media player ( A neotv 550)
same idea as this thread
http://forum.xbmc.org/showthread.php?tid=123648

I have it working in a batch file and xbmc launches it.
Here is the the working batch file.

@echo off
pushd
"C:\Users\htpc\AppData\Roaming\XBMC\userdata\sjcmd.exe" 192.168.123.101 -q CREATESESSION /TYPE=2 /NAME=\"videolist\" /TARGET=\"WILDCHILD22\" /TARGETDEV=\"TV\" /DEVICE=\"fileConfusedmb://:@TOWER2/disk12/testfile.mkv\" /FLAGS=0x2


What do I need to do in a batch file to get xbmc to fill in the file name from my mkv directory and name of the file and start the .bat? I have seen posts using %1 but no sure how to do it.

Any help would be greatly appreciated.
%1 references the first passed parameter to your batch file. Similarly %2 ref's the second, etc.

If you were passing the file name to the batch file, then just put %1 where you want the file name.

For example, say you call:
start.bat filename.txt

You would pass %1 as the file name placeholder:
notepad %1

Take a look at http://www.computerhope.com/batch.htm. It might get funny if the file name has spaces in it.

Ciao.
Yeah I see this but how can I get xbmc to fill in the file name I was on irc and was told I would need to use python. Is their an easier way?
Sorry wildchild22, I obviously miss-understood. I didn't catch the bit about XBMC passing the filename to the batch file. I thought you were executing the batch file manually. D'oh.

So, it basically looks like you are trying to setup an External Player. Have I understood correctly? If so, have you read that wiki link already?

I haven't setup an external player, but there is some config work you need to do in XBMC's playercorefactory.xml file, as the wiki is showing me. It appears the important bit you are worried about is in the "args" node. It passes the filename to the external player you defined (in your case, a batch file). Your batch file will then need the %1 in it to pull the name XBMC has passed.

I don't know how sjcmd needs the filename path (URI) formatted, but there are a couple of options for "args" in how it's passed (it's mentioned in the wiki). You may need to massage the arguments in your batch file.

Also looks like you will need to setup the external player and the rule that executes it in playercorefactory.xml. How your rule needs to be structured, I can't say, as you mention ISO in one part of your post but then say MKV later. But the link you provided and the wiki seems like it covers that bit for you.

I hope that points you in the right direction. Sorry for miss-understanding your intention.
Yes you are correct

I have a little bit more info and an example
I think http: will be easier then the command line proggie. as it is always the same except for the path
this is what needs to be send by http:
for a spy that loves me iso
http://192.168.123.101/sj6.htm?h=PlayMed...so&mtype=2

and all files are the same except for the part after @

http://192.168.123.101/sj6.htm?h=PlayMed...src=smb://@

I am hoping to create a script that will allow me to use %1 variable.


Here is a post from here that may help
https://groups.google.com/forum/#!topic/...sHNW308YzQ

First I created a playercorefactory.xml :
<playercorefactory>
<players>
<player name="Firefox" type="ExternalPlayer" audio="false"
video="true">
<filename>C:\Users\Clayton\AppData\Roaming\XBMC\userdata
\PlayFirefox.bat</filename>
<args>"{1}</args>
<hidexbmc>false</hidexbmc>
<hideconsole>false</hideconsole>
<warpcursor>none</warpcursor>
</player>
</players>
<rules action="prepend">
<rule filetypes="mkv" player="Firefox"/>
</rules>
</playercorefactory>



After that i created a .bat file (PlayerFirefox.bat)
@echo off
rem you can place your PlayBDMV file in \Roaming\XBMC\userdata\
set pth=%1
set compare2=%pth:~1,2%
if "%compare2%"=="Y" (
goto c2tb5
)
:ctb5
set link=http://192.168.0.150/cgi-bin/do?
cmd=start_file_playbackxxxmedia_url=storage_name://%pth%
set link2=%link:\=/%
set link3=%link2:"Y:=Clayton2tb5%
set link4=%link3:xxx=^&%
"C:\Program Files\Mozilla Firefox\firefox.exe" "%link4%" exit
timeout /t 10
taskkill /f /im firefox.exe
When i select a movie (only mkv) in Aenon and push play, the
playercorefactory open the .bat. The .bat now will change the path and
open the link in firefox. After 10s the firefox is close. I will
create a button to change the receiver source to show the dune input,
and another bottom to stop the movie in dune and return to xbmc
input.
Now i have to create a "if" and "goto" for all my HDs because these
hds have differents labels. Very easy, realy.
My client will love this.
Thanks for your help, i forgot about the external player, if you dont
give me this hint i would not have been able to solve the problem.
Clayton








First thing you need to check is how the filepath is being passed by XBMC. I'm just not sure how the "arg" options actually format the output. For example {1} converts to proper UNC mapping for windows file shares (smb). But I don't know if the \ or \\ might screw up the http link you are trying to use. You'll have to test.

[edited] For the %1 to work in your URL, you MAY need to use %1% (in place of where your filename should be) so that it gets expanded correctly. But I think %1 is ok, so maybe it should look something like:
Code:
http://fake.com/?h=PlayMedia.htm?r=0&s=6&bg=5&bt=0&tx=2303769l&src=smb://@%1&mtype=2

If you need to get rid of the \\ in the UNC path that XBMC passes, you could change the set pth and set compare2 statements in the batch file example to something like:
Code:
set pth=%1
set compare2=%pth:~2%
which will drop just the leading \\. Hopefully the browser will accept the \ as valid. If so, then you would use %compare2% instead of the %1 in your URL in your batch file.

If the \ need to be converted to / for whatever reason, you're on your own with the parsing and reconstructing. Big Grin

There looks to be a typo in the playercorefactory example. It's missing a closing quote on the {1} -- i.e. should be "{1}" (quotes included).

Ciao.

Hi thanks for the info so far I have it almost working
I need to use the sjcmd.exe so I dint open and close a browser I think this is the best way.

@echo off
pushd
"C:\userdata\XBMC\userdata\sjcmd.exe" 192.168.123.101 -q CREATESESSION /TYPE=2 /NAME=\"videolist\" /TARGET=\"WILDCHILD22\" /TARGETDEV=\"TV\" /DEVICE=\"file:%1\" /FLAGS=0x2

this is my working scipt the only thing is wrong now is the file name is passed as smb://whaterver... and I need to
add @
so it look like this
smb://@whaterver

How can I do this using the compare command?

Also if file names have spaces I need them to be converted to + so
/James Bond/
would be
/James+Bond/

I am soo close.
Not sure why the file name is being passed with the smb:// from XBMC. The wiki says that args 1 strips that part off and leaves it as \\server\sharename\filename when it is a samba share (assuming windows OS). Unless you left it at args 0 on purpose, which may work better for you.

You can strip the first X characters off the %1 and feed it to a new variable, then pass the new variable to your command. For eg:
Code:
set pth=%1
set compare2=%pth:~X%
Just change the X for whatever number of characters you want to strip off the front of %1. Then feed %compare2% where you had put %1, but hard code the smb://@ in your command. So maybe something like:
Code:
"C:\userdata\XBMC\userdata\sjcmd.exe" 192.168.123.101 -q CREATESESSION /TYPE=2 /NAME=\"videolist\" /TARGET=\"WILDCHILD22\" /TARGETDEV=\"TV\" /DEVICE=\"file:smb://@%compare2%\" /FLAGS=0x2

If sjcmd.exe doesn't understand white spaces in the command, you will have to do some string manipulation. Take a look at DOS string manipulation -- specifically the "Replace" item. Continuing from above, maybe something like:
Code:
set compare2=%compare2: =+%

Ciao.
Thanks so much Jogee

Here is my bat file it is working perfectly Just one last thing I need it to do.
after it is running I need the bat file to wait 5 secs then either press q and then enter
or close the cmd prompt I have searched again on google and cannot find how to to this.


@echo off
set pth=%1
set compare2=%pth:~3%
set compare2=%compare2:\=/%
pushd
"C:\Documents and Settings\Darren\Application Data\XBMC\userdata\sjcmd.exe" 192.168.123.101 -q CREATESESSION /TYPE=2 /NAME=\"videolist\" /TARGET=\"WILDCHILD22\" /TARGETDEV=\"TV\" /DEVICE=\"fileConfusedmb://@%compare2%\" /FLAGS=0x2

I'm not sure I understand. Are you trying to get SJCMD to start, then have the dos windows batch file disappear right away?

If so, take a look at using the START command in front of the call to sjcmd. Type HELP START at a command prompt for all the options.

Ciao.
Well after the batch file runs SJCMD stays open. It is called CMD in task manager. What I want it to do is after the bat file completes close cmd.exe automatically.
I will look into the START option.


right now I need to either hit the x on the cmd window or hit q and enter on the keyboard