10

Whenever I try to execute a batch file, even a simple one, it prints the whole thing out instead of executing it. I have tried it on MS-DOS 3.3 and 4.0, both do this. If I execute each command individually in the command prompt though they work (so if I type "pause" in the command prompt it will pause, same with the other commands). The batch file executes fine in Windows 2000 (the only computer I had that can read 720k floppy disks) My code is below, named test.bat:

@echo off
cls
echo Hello World!
pause

What it looks like when executed, the text saying test at the top being the program name I executed: screen photo

aschipfl
  • 33,626
  • 12
  • 54
  • 99
Narwhal88
  • 101
  • 3
  • 3
    Your file's probably been converted away from msdos line breaks (`\r\n`) and is now a unix text file (`\n` new line) only. or maybe `\l` linefeeds. – Marc B Apr 04 '16 at 21:20
  • Hi, im relatively new to batch coding, and i dont quite understand. Would you mind explaining further? thanks! ps: i typed the program in wordperfect in dos and saved as test.bat if that matters – Narwhal88 Apr 04 '16 at 21:24
  • 3
    don't use a wordprocessor for editing code. can't remember when edit.com became part of dos, but use that instead if it's available - it's a plain text editor. worst case, you can recreate your bat by doing `copy con > test.bat` and typing in your commands, then hitting F6 to finish. – Marc B Apr 04 '16 at 21:26
  • Or plain old (Windows) Notepad, being sure to save the file using ANSI encoding (this is an option near the SAVE button). – Philip Kelley Apr 04 '16 at 21:31
  • Msdos 4.0 seems to not have edit.com. Could i just copy edit.com to 4.0? or would that not work? i cant install dos either as the machine doesnt have a hard drive, its just got 2 720k floppy drives. Im trying to find a plain text editor for 4.0 at the moment. My goal is to use the dos based machine to write the code. A couple reasons for this. its a laptop with cherry mx blue keyboard, and its easier then writing it on a modern computer, copying it to an older computer with usb and then writing it to a 720k floppy disk. – Narwhal88 Apr 04 '16 at 21:35
  • Sorry for double posting, but i figured it would be clearer to post a seperate comment. Marcs second comment solved it. i copied edit.com and qbasic.exe to my disk and typed a simple batch file and it worked. Thanks! – Narwhal88 Apr 04 '16 at 21:54
  • 7
    Upvoting solely because you've used the ms-dos tag and you're _actually using ms-dos_. – SomethingDark Apr 04 '16 at 22:15
  • 2
    @MarcB Repost your comments as an answer so OP can accept it. – rojo Apr 04 '16 at 23:10
  • Upvoting because you have the electronic version of Jurassic Park. – DSway Apr 05 '16 at 21:09

2 Answers2

1

As others have mentioned in the comments, your test.bat file doesn't contain the invisible carriage return characters - only linefeed characters. That's fine for Unix/Linux, but DOS needs both. The whole file is being treated as one line.

Since this is a simple file, you could just retype it with the command copy con test.bat and type CTRL+Z when you are finished. Unfortunately, this will only let you create new files, not edit existing ones.

As you've discovered, MS-DOS 4 predates the edit command. But it did come with another (more annoying) text editor: edlin.

You can only edit one line at a time and the keyboard controls are not exactly intuitive, so check out this link for details on navigating the interface: http://www.computerhope.com/edlin.htm

Dan J.
  • 71
  • 3
0

To make the answer easily accessible to all users:

To prepare and run a DOS batch file in MS DOS:

  1. copy DOS apps edit.com and qbasic.exe to your MS-DOS disk
  2. type your batch file in edit.com, do not use word processors
  3. run it in MS-DOS. It should work fine.
Stephan
  • 53,940
  • 10
  • 58
  • 91
zamarac18
  • 1
  • 2