• Please review our updated Terms and Rules here

MS-DOS.. ECHO without a newline?

Raven

Veteran Member
Joined
Mar 7, 2009
Messages
2,752
Location
DE, USA..
I want to print the output of a program as part of an echo statement without having to redirect I/O to and from a file, because that slows things down unnecessarily.

Basically I just want the comp to:

echo This machine is powered by an `chkcpu/s`

The only problem is the lack of backticks. So if I could do echo without a newline, then I could just run chkcpu/s and it would tack it on. My first thought was to print a backspace character to kill the newline, but I wasn't sure how to do that.

Ideas?
 
I want to print the output of a program as part of an echo statement without having to redirect I/O to and from a file, because that slows things down unnecessarily.

Basically I just want the comp to:

echo This machine is powered by an `chkcpu/s`

The only problem is the lack of backticks. So if I could do echo without a newline, then I could just run chkcpu/s and it would tack it on. My first thought was to print a backspace character to kill the newline, but I wasn't sure how to do that.

Ideas?

As far as I can tell 6.22 wont do it... Perhaps thru a PAUSE, but not by ECHO...
FWIW... :)
 
What is the typical output of the chkcpu /s command?

Moving forward without that info... I don't think you'll have success using a single-line solution, such as "chkcpu /s | echo This machine is powered by an "

Does chkcpu return an errorlevel code that identifies the CPU? Does it give multiple lines of output? A single line? If an errorlevel, then a simple @chkcpu /s (to hide program output) and an if..errorlevel command to echo the correct output should take care of it.

If not, a trick I've used in the past, while not elegant, certainly gets the job done if you have simple output. Send the program output to a small text file, then use a for command to parse the text you need out of that file. I had to use this trick to check the copy success of a backup script I wrote for XP Pro some time back. The output of a successful single-file copy command should always begin with one, so my commands were essentially:

@copy file1 file2 >> temp.txt
set data=0
for /f %%x in (temp.txt) do set data=%%x
if "%data%"=="1" goto copy_success
goto copy_error1

Again... far from elegant, but that backup script works like a charm.

*edit - just realized that /f wasn't available with the for command in MS-DOS 6.22 (though I think it was in 7.0, i.e. Win95 DOS). Regardless, for the single-character search (or single-word search), the above code should work fine, removing the /f, of course.
 
Last edited:
Try the attached--it not only omits the CR-LF, but allows you to echo any 8-bit character. Included is a similar utility for printer output.

(P.S. to Mike--yeah I know it's a huge 232 bytes long, but it was 25 years ago and I was still getting my bearings in MS-DOS programming)
 

Attachments

  • ECO.ZIP
    1.3 KB · Views: 4
Try the attached--it not only omits the CR-LF, but allows you to echo any 8-bit character. Included is a similar utility for printer output.

(P.S. to Mike--yeah I know it's a huge 232 bytes long, but it was 25 years ago and I was still getting my bearings in MS-DOS programming)
Are you talkin' to ME??

Heck, I use an old PC-MAG(?) utility called EMIT and it's a HUGE 13780 bytes (it does have a lot of options though); adding yours to my toolbox.
 
Last edited:
Basically I just want the comp to:

echo This machine is powered by an `chkcpu/s`

The only problem is the lack of backticks. So if I could do echo without a newline, then I could just run chkcpu/s and it would tack it on. My first thought was to print a backspace character to kill the newline, but I wasn't sure how to do that.

Ideas?
Risking to appear un-modest, i would like to advertise my DOSUTILS package, which you can download from here: http://www.bttr-software.de/products/jhoffmann/

The utility PIPESET can do (to a relatively high degree) what the backticks would do under UNIX.
Alternatively you could "abuse" the TIMESTMP utility as a replacement for echo. Specifying the /O switch would suppress the trailing newline, which i introduced for exactly the same purpose as you just need.
 
Correction, I should have used double percents:
@ECHO OFF
for /f "usebackq delims=" %%i in (`chkcpu /s`) do set mycpu=%%i
echo This machine is powered by an %mycpu%

Assuming "chkcpu /s" produces the output you want, of course, with no LEADING newline.
 
I forgot to check this thread yesterday, wow. :eek:

I've tried that one that Anonymous Freak posted (it's what Google informed me of after a long search) and it just keeps telling me I've got a syntax error no matter what I do (I've tried using simple commands like "date" or "echo hi" too).

The output of chkcpu /s is a concise string containing the name and speed of the cpu, i.e., "Am486DX4 101mhz", so an errorlevel check won't work (plus I'll likely want to do similar things for other programs at various points in my batch programming life). What I was doing was redirecting output to a file, reading the file into an environment variable using STRINGS.COM, and then printing it in ECHO, but that took like 5 seconds realtime and I decided it sucked - lol.

Yeah, I was wondering about that. Worth mentioning that this won't work with any 'real' version of DOS, which kind of restricts its use as a universal CPU detector...

I'm just using it to print the currently installed CPU and it's speed in my machine, and I always run DOS 7.10 on machines I'd be interesting in having that print every boot on, so no worries.

Just as a test, btw, I ran the exact line Anonymous Freak wrote and it also produces an ambiguous "Syntax error". I will investigate the tools the others have posted now.

Edit: Dude, holy crap, ECO is fantastic. Do you still have the source for that, Chuck?

Edit 2: I can finally format text how I want... yay... as a programmer I have absolutely no trouble popping \r and \n in where needed, so this is brilliant. It actually reduces the number of commands I need to run because I can insert newlines and/or carriage returns without calling "ECHO" over and over to make new lines.

Example output:
Welcome to MS-DOS 7.10 on the Presario 425.
<sp>This system is powered by the AMD 5x86 134MHz.
C:\>_

(I put <sp> to represent a space as this forum seems to remove leading space in a quote)
 
Last edited:
BTW wiwa64, I found several things - both yours and the site owner's (presuming that isn't also you) that I have downloaded - haven't tested things, but they look quite useful.

lutiana: The majority of that code isn't autodetecting, but I created a batch-file-based system text displayer for DOS that did similar things and more by wrapping several programs with some formatting. I could vastly improve on it with ECO and some other new tools I found today, though.

For the aforementioned batch program, see this thread: http://www.vintage-computer.com/vcforum/showthread.php?20200-DOS-System-Information-Tool

The code for the bit of text in the previous post of mine is as follows:

ECO Welcome to MS-DOS 7.10 on the Presario 425. \r\n This system is powered by
chkcpu/s
ECO .\r\n
ECO \7

The last line produces a beep. If you inspect my DOS System Information Tool in the linked thread you can find how to detect and display DOS version among other things, as well. I'll likely be updating that soon in light of ECO and other tools as mentioned above, however.
 
Found a 4 line PURE batch command way of doing it

Found a 4 line PURE batch command way of doing it

@ECHO OFF
SET /p WordsVar=This machine is powered by an <NUL
chkcpu/s
ECHO.

At least it worked in an XP DOS box.
 
Last edited:
I knew it wouldn't work, but I tried it anyway - GAL's method doesn't work in DOS 7.10.
 
I forgot to check this thread yesterday, wow. :eek:

I've tried that one that Anonymous Freak posted (it's what Google informed me of after a long search) and it just keeps telling me I've got a syntax error no matter what I do (I've tried using simple commands like "date" or "echo hi" too).
Did you read my post#10? That's WinXP etc. CMD syntax, not DOS.

Just use Chuck's ECO or any of the dozens of equivalent enhanced ECHO programs out there and get on with it.
 
MikeS: Um.. I am... why are you so edgy? The problem was solved and I thanked Chuck a bunch of times - this is all just after-conversation.

Chuck: I am not a big fan of 4DOS - whenever I replace the command interpreter DOS feels odd to me.
 
Back
Top