Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  

Batch file help

Recommended Posts

As someone who is just recently opening my eyes to working with batch files, I've been working on a few to simplify many of the tasks I do by hand. I'm a beginner (I pretty much learned all of this today) so forgive me if this is really sloppy. But I'm looking for ways I can condense these tasks so that I don't need to type as much every time.

I want to record a demo with prboom, say WOS.WAD map05. But I also want it to:
1. Generate another batch which I can run to playback the demo (testdemo.bat) The "-geom" bit is because I record demos on a different computer than I watch demos on, so I change the resolution.
2. Add a line to my list of "demos to watch" batch (doomtv.bat)
3. Since I only need to do #1 and #2 once, create a new batch file with those two parts omitted, in case I fail the recording and need to re-record.

Since I have to modify bits and pieces of these giant lines every time I want to change something, like the map number, the skill, the wad, etc., am I able to somehow turn many of these things in the first line into variables or something, and plug them into to the subsequent lines so whenever I change the first line, it will know to change the subsequent lines too?

\DOOM\PRBOOM\prboom-plus.exe -iwad "\DOOM\WADS\IWADS\doom2.wad" -file "\DOOM\WADS\PWADS\idgames\doom2\megawads\wos.wad" -skill 4 -complevel 2 -warp 05 -record "\DOOM\WADS\DEMOS\DOOMTV_wos_05.lmp"

ECHO \DOOM\PRBOOM\prboom-plus.exe -iwad "\DOOM\WADS\IWADS\doom2.wad" -file "\DOOM\WADS\PWADS\idgames\doom2\megawads\wos.wad"  -playdemo "\DOOM\WADS\DEMOS\DOOMTV_wos_05.lmp"  -geom 1366x768f >testdemo.bat

ECHO \DOOM\PRBOOM\prboom-plus.exe -iwad "\DOOM\WADS\IWADS\doom2.wad" -file "\DOOM\WADS\PWADS\idgames\doom2\megawads\wos.wad" -playdemo "\DOOM\WADS\DEMOS\DOOMTV_wos_05.lmp"  -geom 1366x768f >>doomtv.bat

ECHO \DOOM\PRBOOM\prboom-plus.exe -iwad "\DOOM\WADS\IWADS\doom2.wad" -file "\DOOM\WADS\PWADS\idgames\doom2\megawads\wos.wad" -skill 4 -complevel 2 -warp 05 -record "\DOOM\WADS\DEMOS\DOOMTV_wos_05.lmp" >record.bat

Share this post

Link to post

Well, since you admitted to being a beginner and only having started today, why don't you perservere a bit along the path of using variables/command line parameters? I'm sure you'll understand what to do, sooner or later.

Also, do you need to actually generate more "child" .bat files whenever you run a "parent" or "master" file? This can be done if you use output redirection, but you'll also need to handle those long commands as strings...in general the DOS/Windows batch language is much less flexible than what is available on Linux/Unix when it comes to such tasks, but it can be used just as well, only not as elegantly.

In this particular case, I'd probably find it faster to write a small program in C that generates the desired batch files, rather than go through a .BAT crash course and re-learn all the rules, restrictions ane exceptions, but that's your call.

Share this post

Link to post

I did manage to find help by google searching for variables. After a little bit of trial and error I managed to nail it.

set sourceport=\DOOM\PRBOOM\prboom-plus.exe
set iwad="\DOOM\WADS\IWADS\DOOM2.wad"
set pwad1="\DOOM\WADS\PWADS\idgames\doom2\megawads\wos.wad"
set pwad2=
set pwad3=
set pwad4=
set skill=4
set complevel=2
set map=05
set demolump="\DOOM\WADS\DEMOS\DOOMTV_wos_05.lmp"

ECHO %sourceport% -iwad %iwad% -file %pwad1% %pwad2% %pwad3% %pwad4% -skill %skill% -complevel %complevel% -warp %map% -record %demolump% >record.bat
ECHO %sourceport% -iwad %iwad% -file %pwad1% %pwad2% %pwad3% %pwad4% -playdemo %demolump%  -geom 1366x768f >>doomtv.bat
ECHO %sourceport% -iwad %iwad% -file %pwad1% %pwad2% %pwad3% %pwad4% -playdemo %demolump%  -geom 1366x768f >testdemo.bat

%sourceport% -iwad %iwad% -file %pwad1% %pwad2% %pwad3% %pwad4% -skill %skill% -complevel %complevel% -warp %map% -record %demolump%
I also managed to find a batch file someone made that shuffles lines in a text file, so by just running it, it will shuffle all the demo lumps in my "demos to watch" playlist in random order :)

Share this post

Link to post

You nailed it indeed. I wish I had supervised students half as smart as that in the freshman computer labs, being able to go from straight commands to a fully parametrized program in a single lesson, and on their own.

Now, as an exercise for the reader, make some of those parameters being read from the command line, and some being optional/having default values if not provided ;-)

Share this post

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this