Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSDOS prints the whole batch file on screen instead of executing

Tags:

batch-file

dos

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

like image 867
Narwhal88 Avatar asked Apr 04 '16 21:04

Narwhal88


People also ask

How do I close a batch file without closing the window?

Batch file processing ends when execution reaches the end of the batch file. The trick therefore is to use the goto command to jump to a label right before the end of the file, so that execution “falls off the end”.


1 Answers

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

like image 141
Dan J. Avatar answered Oct 19 '22 18:10

Dan J.