Announcement

Collapse
No announcement yet.

What I learned about Batch files that...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • What I learned about Batch files that...

    ".....that I was never taught in school"

    Just a batch thread for discussing some things that might be good to know, especially before you take up Batch writing.

    1. Dos memory is small. It can be inflated, but this is not usually recommended. Environment variables, IE, any variables you assign, seem to have the least space. I've had errors after just assigning 8 or 10 variables in a batch.

    1.a. There are several ways to expand the memory. Actually dozens. MANY of them don't work on all versions of windows, which is why it's best to avoid these kind of solutions if you can. Some of these include 'Create a shortcut to the batch and then use the properties tabs to assign the memory spaces' : wrong, doesn't work in NT or XP. Or, 'change the shell environment' : wrong, you don't want to go messing with people's machine settings if you can help it. Besides which, these things are difficult to do and know where to do.

    1.b. The one method that does seem to apply to all modern DOS, from what I can tell, is "command /C batchfile.bat /E:nnnnn" where n is a number between 160 and something bigger. Dos is typically run with only 256k available, so beefing that up to 1048 or higher is accpetable. the /C is to make it work like a 'call', and return to the line in the existing batch when the called batch is finished. The caveat here is that, though this works, it didn't help me with gaining more environment-variable space anyways. I had to use fewer variables. But it might help you.

    2. Dos versions vary across all the windows environements. There are commands available to XP and NT users that will not work on earlier versions without installing extra files into your core directories.

    3. Desipite #2, most of the best commands are available to machines with any version of Windows. Just avoid things like 'Choice' and some of the low level stuff such as modifying Command.com or things like that.

    4. DOS is not Perl. There are only 10 native batch commands. 10! . Then there are another handful of DOS commands. Don't go writing real scripting with DOS. There's no hope for people who would try to do a recursive decent parser with it. You could do it, but it'd be dumb.

    4.a. DOS is just powerful enough on the other hand. You can do most of the heavy lifting with it. Things like moving files around or even simple scheduling are easy. With so little possibilites, it is not at all hard to learn. Also, though Microsoft would like to see DOS die, it hasn't, so it's a convenient way to set up programs for Winblows machines. It's just that if you want to do real programming, you should do that. DOS is for the simple stuff.

    5. Some simple things you can do without installing another command interpreter (IE perl, winscripting, vb, whatever); This means you can set them up in a flash on a new machine. I like having little batch files to KILL windows and shutdown when other things fail. Many people like to have a simple button to click that will back up all files modified after such-and-such a date, or to destroy all the cookies in your browser, or to merge logfiles, or whatever. If you've never given it a try, I reccomend it. I wish I'd learned DOS first (instead of basic). It's damn simple. Even better, it will screw you up bigtime when you go back to a *nix environment because everything is backwards in DOS.

    No, there is no real point to this thread. But if you do have Batch tips, maybe this would be a good place to put 'em for others on Apolyton. When I did my search I found a lot of references to CivSwap, which got my heart beating fast because I've just written ModSwapper with batch. They are totally different. CivSwap is for in-game settings switchs based on Autosaves. ModSwapper is for installing and uninstalling and auto-install-launching mods for any game. Whew. But there are some people that still use DOS. Now I see why.

    -Smack
    Aldebaran 2.1 for Smax is in Beta Testing. Join us for our first Succession Game

  • #2
    What I've learnt about batch files:

    Never make your Autoexec.bat refer to itself. :/

    Comment


    • #3
      1.b above is also wrong. Command.com and cmd.com vary on the distributions of DOS and windows.

      -S
      Aldebaran 2.1 for Smax is in Beta Testing. Join us for our first Succession Game

      Comment


      • #4
        I could use some help getting this to work on various Windows installs. If you could download and report any errors and/or help me debug, that'd be great. I get no errors on my machine. It swaps 60+files and launches terranx.exe with one click. Let me know what Windows you are running if you get an error.

        -S
        Aldebaran 2.1 for Smax is in Beta Testing. Join us for our first Succession Game

        Comment


        • #5
          You can make the first batch file in a program call itself:

          Code:
          @echo off
          if not "%1"=="READY" command /E:4096 /C %0.bat READY
          Will re-run the batchfile and allocate 4k of environment space. Even the spammiest batchfiles I've seen (in terms of env-vars) can't fill that.

          Test the env-var %OS% to find wether or not you have cmd on the system.

          go to http://www.nu2.nu and you can get a freeware version of choice called bchoice (Bart's choice). Compatible with all Windows >9x but not puredos.

          Try looking for a program called batchman (freeware). really nifty batch file tool, or find a copy of WBAT (also freeware) for doing dialogs.

          Some of the stuff you can do with dos is really quite scary, especially since some people like to port unix utilities of good to windows.

          the rundll32 command is handy, since you can call some windows api calles with it.

          That's all I can think of now.
          #play s.-cd#g+c-ga#+dgfg#+cf----q.c
          #endgame

          Quantum P. is a champion: http://geocities.com/zztexpert/docs/upoprgv4.html

          Comment


          • #6
            Here's a really obscure one:

            running a batchfile that calls another batchfile with

            command /E:4096 /C blah.bat

            in which blah.bat calls another batch file, during or after the call any if statements featuring at least one user-defined environment variable (eg not %1, etc.) will throw "Bad Command or File Name"
            #play s.-cd#g+c-ga#+dgfg#+cf----q.c
            #endgame

            Quantum P. is a champion: http://geocities.com/zztexpert/docs/upoprgv4.html

            Comment


            • #7
              Ech. That is badly obscure. Looks like a hard one to trace. Glad you squished it.
              Aldebaran 2.1 for Smax is in Beta Testing. Join us for our first Succession Game

              Comment


              • #8
                Pre-NT (I think) versions of windows don't like multiple pipes

                Code:
                tfind /h "Aldebaran 2" aldeb205.sm | tfind /v "Aldebaran 2" | lmod set filename=[$!]
                works just fine on 2k but for ME (and probably below) you need:

                Code:
                tfind /h "Aldebaran 2" aldeb205.sm>temp.txt
                tfind /v "Aldebaran 2" temp.txt | lmod set filename=[$!]
                del temp.txt
                to get the same result.
                #play s.-cd#g+c-ga#+dgfg#+cf----q.c
                #endgame

                Quantum P. is a champion: http://geocities.com/zztexpert/docs/upoprgv4.html

                Comment


                • #9
                  And just to contradict my above post, only the 9x windows doesn't seem to like many pipes. The following works great under puredos:

                  Code:
                  ipconfg | tfind "IP Address" | lmod my_ip = [$!]>>kahn.cfg
                  #play s.-cd#g+c-ga#+dgfg#+cf----q.c
                  #endgame

                  Quantum P. is a champion: http://geocities.com/zztexpert/docs/upoprgv4.html

                  Comment

                  Working...
                  X