0

I want to write a new file using a batch script. I want to have the bat prompt me for the file name, i think I have that "set /P file=Enter File Name:" then put that name in for the name of the file, and that same name 5 places in the file and save the file as that file name.smil See what I have, I know this is not right but hopefully you can see what I am trying to do.

set /P file=Enter File Name:

<?xml version="1.0" encoding="UTF-8"?>
<smil title="%file%">
<body>
    <switch>
        <video height="1080" src="%file%-1080.mp4"
        systemLanguage="eng" width="1920">
            <param name="videoBitrate" value="5000000" valuetype="data"></param>
            <param name="audioBitrate" value="320000" valuetype="data"></param>
        </video>
        <video height="720" src="%file%-720.mp4"
        systemLanguage="eng" width="1280">
            <param name="videoBitrate" value="3000000" valuetype="data"></param>
            <param name="audioBitrate" value="192000" valuetype="data"></param>
        </video>
        <video height="540" src="%file%-540.mp4"
        systemLanguage="eng" width="960">
            <param name="videoBitrate" value="1500000" valuetype="data"></param>
            <param name="audioBitrate" value="128000" valuetype="data"></param>
        </video>
        <video height="360" src="%file%-360.mp4"
        systemLanguage="eng" width="640">
            <param name="videoBitrate" value="750000" valuetype="data"></param>
            <param name="audioBitrate" value="96000" valuetype="data"></param>
        </video>
    </switch>
</body>
</smil>
  • Related:http://stackoverflow.com/questions/60034/how-can-you-find-and-replace-text-in-a-file-using-the-windows-command-line-envir – Thomas Weller Jun 13 '16 at 21:27

4 Answers4

0

I could not figure out how to make it work with multiline xml, so I ended with this monster:

@echo off

set /p name=Enter File Name:

set file=C:\Temp\%name%.smil

echo ^<?xml version=^"1.0^" encoding=^"UTF-8^"?^> > %file%
echo ^<smil title=^"%name%^"^> >> %file%
echo ^<body^> >> %file%
echo     ^<switch^> >> %file%
echo         ^<video height=^"1080^" src=^"%name%-1080.mp4^" >> %file%
echo         systemLanguage=^"eng^" width=^"1920^"^> >> %file%
echo             ^<param name=^"videoBitrate^" value=^"5000000^" valuetype=^"data^"^>^</param^> >> %file%
echo             ^<param name=^"audioBitrate^" value=^"320000^" valuetype=^"data^"^>^</param^> >> %file%
echo         ^</video^> >> %file%
echo         ^<video height=^"720^" src=^"%name%-720.mp4^" >> %file%
echo         systemLanguage=^"eng^" width=^"1280^"^> >> %file%
echo             ^<param name=^"videoBitrate^" value=^"3000000^" valuetype=^"data^"^>^</param^> >> %file%
echo             ^<param name=^"audioBitrate^" value=^"192000^" valuetype=^"data^"^>^</param^> >> %file%
echo         ^</video^> >> %file%
echo         ^<video height=^"540^" src=^"%name%-540.mp4^" >> %file%
echo         systemLanguage=^"eng^" width=^"960^"^> >> %file%
echo             ^<param name=^"videoBitrate^" value=^"1500000^" valuetype=^"data^"^>^</param^> >> %file%
echo             ^<param name=^"audioBitrate^" value=^"128000^" valuetype=^"data^"^>^</param^> >> %file%
echo         ^</video^> >> %file%
echo         ^<video height=^"360^" src=^"%name%-360.mp4^" >> %file%
echo         systemLanguage=^"eng^" width=^"640^"^> >> %file%
echo             ^<param name=^"videoBitrate^" value=^"750000^" valuetype=^"data^"^>^</param^> >> %file%
echo             ^<param name=^"audioBitrate^" value=^"96000^" valuetype=^"data^"^>^</param^> >> %file%
echo         ^</video^> >> %file%
echo     ^</switch^> >> %file%
echo ^</body^> >> %file%
echo ^</smil^> >> %file%

pause
Slai
  • 22,144
  • 5
  • 45
  • 53
  • also how can I ad a path to where I want the file saved? – user3447105 Jun 13 '16 at 22:25
  • `%path%` is a systemvariable. Please don't change it. Windows uses this variable to know where to look for it's executables. If you change it, most commands won't work anymore. It works here, because you use only the `echo` and `pause` commands, which happens to be internal commands. – Stephan Jun 14 '16 at 07:12
0

still having a problem getting this to all run at one time,

set /P file=Enter input File Name:
set /P fileext=Enter input File Extension: 

handbrakecli -i "C:\Users\John\Desktop\VIDEO\%file%.%fileext%" -o "\\s2016p5-plex\c$\Program Files (x86)\Wowza Media Systems\Wowza Streaming Engine 4.3.0\content\%file%-1080.mp4" -w 1920 --preset="Normal" -E av_aac -B 320 -6 stereo
handbrakecli -i "C:\Users\John\Desktop\VIDEO\%file%.%fileext%" -o "\\s2016p5-plex\c$\Program Files (x86)\Wowza Media Systems\Wowza Streaming Engine 4.3.0\content\%file%-720.mp4" -w 1280 --preset="Normal" -E av_aac -B 192 -6 stereo
handbrakecli -i "C:\Users\John\Desktop\VIDEO\%file%.%fileext%" -o "\\s2016p5-plex\c$\Program Files (x86)\Wowza Media Systems\Wowza Streaming Engine 4.3.0\content\%file%-540.mp4" -w 960 --preset="Normal" -E av_aac -B 128 -6 stereo
handbrakecli -i "C:\Users\John\Desktop\VIDEO\%file%.%fileext%" -o "\\s2016p5-plex\c$\Program Files (x86)\Wowza Media Systems\Wowza Streaming Engine 4.3.0\content\%file%-360.mp4" -w 640 --preset="Normal" -E av_aac -B 96 -6 stereo

@echo off

set path=\\s2016p5-plex\c$\Program Files (x86)\Wowza Media Systems\Wowza Streaming Engine 4.3.0\content\%file%.smil

echo ^<?xml version=^"1.0^" encoding=^"UTF-8^"?^> > %path%
echo ^<smil title=^"%file%^"^> >> %path%
echo ^<body^> >> %path%
echo     ^<switch^> >> %path%
echo         ^<video height=^"1080^" src=^"%file%-1080.mp4^" >> %path%
echo         systemLanguage=^"eng^" width=^"1920^"^> >> %path%
echo             ^<param name=^"videoBitrate^" value=^"5000000^" valuetype=^"data^"^>^</param^> >> %path%
echo             ^<param name=^"audioBitrate^" value=^"320000^" valuetype=^"data^"^>^</param^> >> %path%
echo         ^</video^> >> %path%
echo         ^<video height=^"720^" src=^"%file%-720.mp4^" >> %path%
echo         systemLanguage=^"eng^" width=^"1280^"^> >> %path%
echo             ^<param name=^"videoBitrate^" value=^"3000000^" valuetype=^"data^"^>^</param^> >> %path%
echo             ^<param name=^"audioBitrate^" value=^"192000^" valuetype=^"data^"^>^</param^> >> %path%
echo         ^</video^> >> %path%
echo         ^<video height=^"540^" src=^"%file%-540.mp4^" >> %path%
echo         systemLanguage=^"eng^" width=^"960^"^> >> %path%
echo             ^<param name=^"videoBitrate^" value=^"1500000^" valuetype=^"data^"^>^</param^> >> %path%
echo             ^<param name=^"audioBitrate^" value=^"128000^" valuetype=^"data^"^>^</param^> >> %path%
echo         ^</video^> >> %path%
echo         ^<video height=^"360^" src=^"%file%-360.mp4^" >> %path%
echo         systemLanguage=^"eng^" width=^"640^"^> >> %path%
echo             ^<param name=^"videoBitrate^" value=^"750000^" valuetype=^"data^"^>^</param^> >> %path%
echo             ^<param name=^"audioBitrate^" value=^"96000^" valuetype=^"data^"^>^</param^> >> %path%
echo         ^</video^> >> %path%
echo     ^</switch^> >> %path%
echo ^</body^> >> %path%
echo ^</smil^> >> %path%

exit
  • remove `@echo off` and try the path in quotes `set path="\\s2016p5-plex\c$\Program Files (x86)\Wowza Media Systems\Wowza Streaming Engine 4.3.0\content\%file%.smil"` – Slai Jun 13 '16 at 23:19
  • I think batch script does not support network paths, so you can try mapping it to a drive letter `net use Z: \\s2016p5-plex\c$` and then maybe `set path=Z:\Program Files (x86)\Wowza Media Systems\Wowza Streaming Engine 4.3.0\content\%file%.smil` – Slai Jun 13 '16 at 23:30
  • thats it, works great, this will save me a lot of time. thanks – user3447105 Jun 14 '16 at 00:01
  • `%path%` is a systemvariable. Please don't change it. Windows uses this variable to know where to look for it's executables. If you change it, most commands won't work anymore. It works here, because you use only the `echo` and `pause` commands, which happens to be internal commands. – Stephan Jun 14 '16 at 07:12
  • Thanks Stephan, I totally forgot about that as I use a path variable name in programming too often. – Slai Jun 14 '16 at 12:42
  • FYI: the \\path works fine on my Domain to the Hyper-V Server – user3447105 Jun 14 '16 at 23:03
0

This is what I ended up with and it works great, thanks for you help.

set /P file=Enter input File Name:
set /P fileext=Enter input File Extension: 

handbrakecli -i "C:\Users\John\Desktop\VIDEO\%file%.%fileext%" -o "\\s2016p5-plex\c$\Program Files (x86)\Wowza Media Systems\Wowza Streaming Engine 4.3.0\content\%file%-1080.mp4" -w 1920 --preset="Normal" -E av_aac -B 320 -6 stereo
handbrakecli -i "C:\Users\John\Desktop\VIDEO\%file%.%fileext%" -o "\\s2016p5-plex\c$\Program Files (x86)\Wowza Media Systems\Wowza Streaming Engine 4.3.0\content\%file%-720.mp4" -w 1280 --preset="Normal" -E av_aac -B 192 -6 stereo
handbrakecli -i "C:\Users\John\Desktop\VIDEO\%file%.%fileext%" -o "\\s2016p5-plex\c$\Program Files (x86)\Wowza Media Systems\Wowza Streaming Engine 4.3.0\content\%file%-540.mp4" -w 960 --preset="Normal" -E av_aac -B 128 -6 stereo
handbrakecli -i "C:\Users\John\Desktop\VIDEO\%file%.%fileext%" -o "\\s2016p5-plex\c$\Program Files (x86)\Wowza Media Systems\Wowza Streaming Engine 4.3.0\content\%file%-360.mp4" -w 640 --preset="Normal" -E av_aac -B 96 -6 stereo

set path="\\s2016p5-plex\c$\Program Files (x86)\Wowza Media Systems\Wowza Streaming Engine 4.3.0\content\%file%.smil"

@echo off

echo ^<?xml version=^"1.0^" encoding=^"UTF-8^"?^> > %path%
echo ^<smil title=^"%file%^"^> >> %path%
echo ^<body^> >> %path%
echo     ^<switch^> >> %path%
echo         ^<video height=^"1080^" src=^"%file%-1080.mp4^" >> %path%
echo         systemLanguage=^"eng^" width=^"1920^"^> >> %path%
echo             ^<param name=^"videoBitrate^" value=^"5000000^" valuetype=^"data^"^>^</param^> >> %path%
echo             ^<param name=^"audioBitrate^" value=^"320000^" valuetype=^"data^"^>^</param^> >> %path%
echo         ^</video^> >> %path%
echo         ^<video height=^"720^" src=^"%file%-720.mp4^" >> %path%
echo         systemLanguage=^"eng^" width=^"1280^"^> >> %path%
echo             ^<param name=^"videoBitrate^" value=^"3000000^" valuetype=^"data^"^>^</param^> >> %path%
echo             ^<param name=^"audioBitrate^" value=^"192000^" valuetype=^"data^"^>^</param^> >> %path%
echo         ^</video^> >> %path%
echo         ^<video height=^"540^" src=^"%file%-540.mp4^" >> %path%
echo         systemLanguage=^"eng^" width=^"960^"^> >> %path%
echo             ^<param name=^"videoBitrate^" value=^"1500000^" valuetype=^"data^"^>^</param^> >> %path%
echo             ^<param name=^"audioBitrate^" value=^"128000^" valuetype=^"data^"^>^</param^> >> %path%
echo         ^</video^> >> %path%
echo         ^<video height=^"360^" src=^"%file%-360.mp4^" >> %path%
echo         systemLanguage=^"eng^" width=^"640^"^> >> %path%
echo             ^<param name=^"videoBitrate^" value=^"750000^" valuetype=^"data^"^>^</param^> >> %path%
echo             ^<param name=^"audioBitrate^" value=^"96000^" valuetype=^"data^"^>^</param^> >> %path%
echo         ^</video^> >> %path%
echo     ^</switch^> >> %path%
echo ^</body^> >> %path%
echo ^</smil^> >> %path%

exit
0

speaking of the %path$.

Is there a way to add this path to all with set path. Right now the path is in 5 places. if I could just change in one place and have it work in all 5?

\\s2016p5-plex\c$\Program Files (x86)\Wowza Media Systems\Wowza Streaming Engine 4.3.0\content\