views:

205

answers:

7

In my new project I need to use batch files(many of them), but now I need to know about they and where can I read some good tutorials to use they very good ;)

PS: I need to distribute my application for end-users.

A: 

You can start with: Command Line = PowerShell / bash / zsh / ...

Batch is very old-fashioned and practically obsolete now.

Mark Byers
Old-fashioned: yes. Awkward to use: yes. Obsolete: Definitely no. It's still a very valid and viable option that runs on nearly every Windows system out there (not counting WinDOS which is hopefully really extinct by now).
Joey
Yes batch is a viable option, but so is PowerShell. And PowerShell is easier to use. Five years ago perhaps you could say batch was the only option for Windows users (errr... VBScript?), but I disagree that command line = batch now.
Mark Byers
VBScript is a point. PowerShell not. Go ahead, look at random computers and tell me what percentage of users has PowerShell installed. For some things it's simply not desirable to have too many prerequisites. And nearly everything that is forcibly done in batch tends to count into that area.
Joey
@Mark: The problem with PowerShell is that the question wasn't about PowerShell. It's about batch files, not PowerShell scripts. Therefore, PowerShell is not an answer.
Ken White
Sorry Ken, but he changed the question after I posted it. Before it said he wanted to do command line stuff, and assumed that batch was the only way. My answer no longer applies because he changed it. I'll leave my answer anyway in case others find it useful.
Mark Byers
A: 

The one thing I can recommend if you're working with batch scripts in Windows is learn PowerShell. It's a souped up command line that will allow you to interact with any .net object.

Have fun!

T Pops
+3  A: 

Well, learning by doing is probably the best way. There are many pitfalls and weirdnesses in the batch language, making some tasks very much non-fun to do. But I think one should at least stepped into each trap once :-)

References are for example (sometimes with extensive examples for specific usage scenarios):

Specific problems and solutions may be found on sites like Rosetta Code but there aren't many (and I still didn't get around cleaning up there; the batch examples are horrible). I maintain a few tricks on my own site as well (currently under maintenance, though; struggling with my syntax highlighter).

Others have mentioned it: If you have the option, then by all means use other technologies. PowerShell is a nice one but not included by default on older Windows systems, including Vista. For many more complex tasks VBScript via WSH is usually a better option as it has a similar installed base and is way more powerful.

Depending on your requirements this may or may not be possible, but take it into consideration if it may be an option.

Joey
A: 

Besides everything that was suggested, I can recommend using VBScript (.vbs). To use Powershell, you need to install it (although it might be installed along with Windows Updates). To use VBScript (which is also very powerful) you don't need anything, it's in Windows by default.

Vitaly
VBScript support might be disabled by security settings or group policies. Also, the question wasn't about VBScript; it was about batch files. Answer the original question first, and then feel free to offer alternatives. But you have to answer the original question.
Ken White
Ken, you can only "disable" it by renaming the extension association for Wscript.exe or Cscript.exe or deleting those .exe files. And yes, you can even delete windows and install Linux and do not have it. But thanks for your very useful comment.
Vitaly
@ken, the word batch is very loosely defined. batch files run a series of commands to perform a job. if i write a vbscript, save it as myscript.vbs and then put it in a file called test.bat, is it still a batch file? why not, it runs wscript.exe or cscript.exe, much the same as any other command line tools..
ghostdog74
+1  A: 

Basically with bat/cmd files you are running DOS commands (with extra programs/features available to Windows) with each command on a new line.

The .cmd extension is prefereable to .bat on older Windows systems as it runs with cmd.exe, which executes faster than the older command.com. On newer systems (XP and above I think) then it doesn't matter if it is .cmd or .bat then they get executed by cmd.exe.

Here's some tips/examples on writing batch files: http://www.ericphelps.com/batch/

Wikipedia has a list of DOS commands here: http://en.wikipedia.org/wiki/List%5Fof%5FDOS%5Fcommands

Here's some info on invoking the actual cmd.exe http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx?mfr=true

Stuntbeaver
+1  A: 

While I usually don't like MSDN, in this case its documentation on batch files seems fairly decent.

Jason S
A: 

On Windows, use Start|Help and Support Center, and search on "Using batch files", and then in the list of topics under "Overviews, Articles and Tutorials" in the Suggested Topics, click on "Batch files". You'll find links to using parameters, filters and redirection, as well as reference links for batch commands like CALL, ECHO, FOR, and so forth.

The one advantage of batch files over PowerShell is that PowerShell may not be installed, while the command processor (CMD.EXE, or the older DOS version COMMAND.COM) will definitely be there.

Ken White