topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Monday March 18, 2024, 11:34 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Last post Author Topic: DOS Batch Functions Tutorial  (Read 18147 times)

justice

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • View Profile
    • Donate to Member
DOS Batch Functions Tutorial
« on: June 16, 2011, 09:44 AM »
As part of the development of an app, I'm doing the build process using the batch file. I might write a bit more about this at a later date. As the batch file grew I was wondering if it could do functions, to avoid using the same code multiple times. This page is a really good resource (http://www.dostips.c.../DtTutoFunctions.php):


2011-06-16_154114.png




Renegade

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,288
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
Re: DOS Batch Functions Tutorial
« Reply #1 on: June 16, 2011, 10:06 AM »
You might want to look into PowerShell as it has largely replaced batch files for a lot of admins.

But, batch files do have their appeal still! (I use some batch commands in build processes and whatnot.) Those look like some nice tuts! :)
Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker

daddydave

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 867
  • test
    • View Profile
    • Donate to Member
Re: DOS Batch Functions Tutorial
« Reply #2 on: June 16, 2011, 11:13 AM »
See https://www.donation...ex.php?topic=22441.0

EDIT: Sorry the above link was a bit off topic. You didn't really ask for other batch file resources, did you? I will check out the link you gave. It's very handy to be able to use functions in batch files. :Thmbsup:

One big advantage of batch files is you don't have to install anything, so you can use them in restricted environments (i.e., work).
« Last Edit: June 16, 2011, 12:57 PM by daddydave »

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,540
  • @Slartibartfarst
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: DOS Batch Functions Tutorial
« Reply #3 on: June 17, 2011, 12:41 AM »
IMHO, the best thing to do with DOS batch commands is avoid using them.
Try Take Command from JP Software.
I used to use the precursor to Take Command, called 4DOS. It was superb. I gather from Wikipedia that 4DOS is pseudo public domain now.

mwb1100

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,645
    • View Profile
    • Donate to Member
Re: DOS Batch Functions Tutorial
« Reply #4 on: June 17, 2011, 02:15 AM »
One big advantage of batch files is you don't have to install anything, so you can use them in restricted environments (i.e., work).

That's the only advantage.  But it's a compelling one.

The book "Windows NT Shell Scripting" by Timothy Hill has about the best coverage of how to do complex processing with batch files that I've come across (get a used/remaindered one for the cost of shipping).

But I'd avoid doing anything too complex with batch files unless you really, really have to.  There are so many far better tools available (and most of them free).  But you do usually have to make sure they're installed (or that a runtime is) if the script you're coming up with has to be able to run on machines you don't control.

AutoHotKey (and friends) is one of the exceptions as I understand it - build the script to an exe and nothing else is needed on the end-user's machine (I imagine that's one of the reasons it's quite popular on DC's coding snacks).

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: DOS Batch Functions Tutorial
« Reply #5 on: June 17, 2011, 03:14 AM »

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: DOS Batch Functions Tutorial
« Reply #6 on: June 17, 2011, 04:00 AM »
The book "Windows NT Shell Scripting" by Timothy Hill has about the best coverage of how to do complex processing with batch files that I've come across (get a used/remaindered one for the cost of shipping).

FWIW, Chapter 5 appears to be online.

AutoHotKey (and friends) is one of the exceptions as I understand it - build the script to an exe and nothing else is needed on the end-user's machine (I imagine that's one of the reasons it's quite popular on DC's coding snacks).
-mwb1100

If I may digress a bit... :)

Curious who you regard as "friends" -- AutoIt3 perhaps?  Any others?

Some things that I found attractive about AHK / AutoIt3 included:

  • Conditions of use (e.g. free to obtain and produced output freely usable)
  • Relatively small resulting exe
  • Actively developed with a community of users
  • Decent selection of reusable code / libraries

For the things I checked some months ago, other things didn't seem to match these  -- e.g. as I understand it, it's possible to create single exes for Perl and Python, but I don't think the results end up nearly as small as for AHK / AutoIt3.  IDLE (based on Lua) seemed to produce relatively small exes, but the last time I checked there didn't seem to be much of a community and development didn't seem terribly active.  Not sure about Factor yet -- still need to see how big the resulting exes are.

Curious to hear others thoughts on this topic...perhaps another topic / thread is in order...

justice

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • View Profile
    • Donate to Member
Re: DOS Batch Functions Tutorial
« Reply #7 on: June 17, 2011, 04:08 AM »
I was looking to discuss the very same topic ewemoa.

oblivion

  • Supporting Member
  • Joined in 2010
  • **
  • Posts: 491
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: DOS Batch Functions Tutorial
« Reply #8 on: June 17, 2011, 07:47 AM »
I was looking to discuss the very same topic ewemoa.
I've been using a little freebie called BatchCompiler for some years, as a way to lock down batchfiles against casual modification and ensure maximum portability. (Can't remember where I got it now, and the readme only quotes the author's name -- Ricardo Arias -- but hey, Google is your friend.)

There are batchy things that it doesn't do well -- can't remember for sure, now, but CALLs might be one of those things -- but there are usually more than one way to skin the relevant cat and I've never found another batch compiler that worked as well.

Add in something like Reshacker so you can plug in your icon of choice and Tah Dahhh!
-- bests, Tim

...this space unintentionally left blank.

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: DOS Batch Functions Tutorial
« Reply #9 on: June 17, 2011, 04:16 PM »
I've been using a little freebie called BatchCompiler for some years, as a way to lock down batchfiles against casual modification and ensure maximum portability. (Can't remember where I got it now, and the readme only quotes the author's name -- Ricardo Arias -- but hey, Google is your friend.)
Apparently, I wasn't Google's really good friend today :(

But I came across the following instead on a thread that mentioned BatchCompiler:

  Bat To Exe Converter

Haven't tried it yet though.

justice

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • View Profile
    • Donate to Member
Re: DOS Batch Functions Tutorial
« Reply #10 on: June 18, 2011, 05:30 AM »
What's the point of making them exe files.
Code: Autohotkey [Select]
  1. SetWorkingDir %A_ScriptDir%  
  2. BatchFile = test.bat
  3. FieInstall, %BatchFile%,%A_Temp%
  4. RunWait, %A_Temp%\%BatchFile%,%A_WorkingDir%
  5. FileDelete, %A_Temp%\%BatchFile%

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: DOS Batch Functions Tutorial
« Reply #11 on: June 18, 2011, 05:49 AM »
Never figured out how to have a batch file have a custom icon, whereas this is possible for an exe.

oblivion

  • Supporting Member
  • Joined in 2010
  • **
  • Posts: 491
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: DOS Batch Functions Tutorial
« Reply #12 on: June 18, 2011, 02:31 PM »
I've been using a little freebie called BatchCompiler for some years, as a way to lock down batchfiles against casual modification and ensure maximum portability. (Can't remember where I got it now, and the readme only quotes the author's name -- Ricardo Arias -- but hey, Google is your friend.)
Apparently, I wasn't Google's really good friend today :(
Obviously I should check these rash statements before I make them.

My copy of BatchCompiler's on a machine I'm not going to be anywhere near for another week, but if you want a look I've definitely got the original distribution zipfile on there, so if you don't find it beforehand, let me know your email privately and I'll get it to you sometime on the 27th. It's quite old, from memory, maybe 2003, so I guess the author decided he wasn't going to carry on supporting it...
-- bests, Tim

...this space unintentionally left blank.

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: DOS Batch Functions Tutorial
« Reply #13 on: June 18, 2011, 04:24 PM »
Thanks for the offer  :)

Perhaps I'll attempt another round at searching, but I start to wonder whether it's such a wise idea for me to make a habit out of using a tool which doesn't appear to be maintained...hmmm...

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,540
  • @Slartibartfarst
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: DOS Batch Functions Tutorial
« Reply #14 on: June 18, 2011, 09:24 PM »
@oblivion
@ewemoa:                Re: Batch Compiler.

From memory, there was a batch compiler in 4DOS (I referred to 4DOS in a post above), but I never actually needed to use it except to try it out, so cannot comment on it.
I did some googling using "Batch Compiler Ricardo Arias" search terms. I did find links/references to those terms - mostly in the Spanish language - but no download source for the Batch Compiler.
On one site Purebasic.com there was this "user opinion":
Ricardo Arias, Argentina
"I come from Visual Basic.
Then I was searching for something small, with no runtimes, speed and easy too.
Maybe PureBasic doesn't have that quantity of sourcecode available, but a great community that always help each other."
(By the way, reading about it on that site, I thought that PureBasic looked like a great Basic language + compiler. I might try it out,)     :)

I also found this link: a Batch to EXE Converter on F2K0.de
You can download it from there, but it's probably not the Batch Compiler from Ricardo Arias.

oblivion

  • Supporting Member
  • Joined in 2010
  • **
  • Posts: 491
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: DOS Batch Functions Tutorial
« Reply #15 on: July 04, 2011, 05:45 AM »
[
From memory, there was a batch compiler in 4DOS (I referred to 4DOS in a post above), but I never actually needed to use it except to try it out, so cannot comment on it.
I remember looking into it -- I used and loved 4DOS for years -- but it was a separate license fee, particularly if you wanted to distribute things you'd made with it, I think.

I have now found the source zip for Batchcompiler. If anyone wants it, PM me and I'll email it. (The zipfile is only 14.6k)
-- bests, Tim

...this space unintentionally left blank.

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,540
  • @Slartibartfarst
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: DOS Batch Functions Tutorial
« Reply #16 on: July 15, 2011, 09:57 PM »
Batch Compiler 1.0.1 By Ricardo Arias
Oblivion kindly emailed me the batch compiler and I have put it in box.net for downloading from here: BatchCompiler.zip

kyrathaba

  • N.A.N.Y. Organizer
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 3,200
    • View Profile
    • Donate to Member
Re: DOS Batch Functions Tutorial
« Reply #17 on: August 07, 2011, 03:19 PM »
Thanks.  Downloaded this!

db90h

  • Coding Snacks Author
  • Charter Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 481
  • Software Engineer
    • View Profile
    • Bitsum - Take control of your PC
    • Read more about this member.
    • Donate to Member
Re: DOS Batch Functions Tutorial
« Reply #18 on: August 07, 2011, 04:04 PM »
I guess nobody has taken to PowerShell yet, eh? ;). It is quite powerful, though I never thought a command line scripting shell could consume so many resources, lol. It is one massive beast. I dunno if anyone, even network engineers, have 'taken' to it yet.

Personally, I love Cygwin on Windows. Let's me have linux style scripting in Windows. Of course, I still use plenty of BATCH file for automation to this day.

worstje

  • Honorary Member
  • Joined in 2009
  • **
  • Posts: 588
  • The Gent with the White Hat
    • View Profile
    • Donate to Member
Re: DOS Batch Functions Tutorial
« Reply #19 on: August 07, 2011, 04:41 PM »
I'd love to learn / get a hang of PowerShell. The problem is I have no clue what I can do with it that will make a time investment worth it, and I personally would probably be best served a set of ready-made scripts and examples that just let me be productive right off the bat. :)

Back on topic-ish now... Batch files I haven't really needed in years, and the looping facilities in it just make me cringe. Python usually sees to all my needs in that sense.

db90h

  • Coding Snacks Author
  • Charter Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 481
  • Software Engineer
    • View Profile
    • Bitsum - Take control of your PC
    • Read more about this member.
    • Donate to Member
Re: DOS Batch Functions Tutorial
« Reply #20 on: August 07, 2011, 04:50 PM »
Yes, BATCH files weren't designed for complex scripting at all. Not like *nix shells, which were designed that way from the start. I still prefer *nix.

PowerShell, despite it being a resource hog like you wouldn't imagine, is very powerful. It can let you script almost anything you could code in .NET, minus all the UI stuff maybe. At least, that's my understanding of it. I have not taken the time to learn, nor care to learn, the internals of it either. Whether the product even survives remains to be seen. I'm sure some network admins are using it for some automation tasks, but that's about it. Nobody really took to it. They'd do better off pushing their POSIX subsystem on admins, and give them an interface common to Windows and linux. Of course, the *nix style scripting came from decades ago and isn't the most efficient thing in the world, but with the help of numerous facilitating tools you can do pretty much anything you want. PowerShell could have been much more efficient, and might be for large and very complex scripts, though its .NET MSIL overhead makes it slow .. so who knows on that one. They *did* include some unix commands in PowerShell, ironically.. at least named the same, different options and output format -- just to confuse people.

kyrathaba

  • N.A.N.Y. Organizer
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 3,200
    • View Profile
    • Donate to Member
Re: DOS Batch Functions Tutorial
« Reply #21 on: August 07, 2011, 08:32 PM »
though its .NET MSIL overhead makes it slow ..


Ah, but slow relative to what?  I can't imagine PowerShell programs being speed-critical.

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,540
  • @Slartibartfarst
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: DOS Batch Functions Tutorial
« Reply #22 on: September 09, 2011, 11:29 PM »
Rather than a DOS batch functions tutorial, would it be of more current relevance to use Window Scripting?
There's an interesting post about it here: Better Than Batch: A Windows Scripting Host Tutorial

Just a thought.

kyrathaba

  • N.A.N.Y. Organizer
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 3,200
    • View Profile
    • Donate to Member
Re: DOS Batch Functions Tutorial
« Reply #23 on: September 10, 2011, 11:54 AM »
+1.

I think that, in general, WS would be preferable, although there might be so esoteric situations where a small batch file might be preferable.

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,540
  • @Slartibartfarst
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: DOS Batch Functions Tutorial
« Reply #24 on: September 11, 2011, 01:26 AM »
@kyrathaba: I didn't know anything about Windows Scripting until I read that post.
I am not sure, but maybe this is what @mwb1100 was referring to when he wrote in the above thread:
The book "Windows NT Shell Scripting" by Timothy Hill has about the best coverage of how to do complex processing with batch files that I've come across (get a used/remaindered one for the cost of shipping).

@justice: Could this (Windows Scripting) be a potential alternative answer to what your original Q was about? (I ask the question in gnorance as to what your full requirements might be or why they might have necessitated the use of DOS batch in the first place.)