Image Map Image Map
Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: MS-DOS.. ECHO without a newline?

  1. #1
    Join Date
    Mar 2009
    Location
    DE, USA..
    Posts
    2,701

    Default MS-DOS.. ECHO without a newline?

    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?
    Resident Self-Proclaimed 486 and Pentium-class Machine Expert
    More commonly known as "Yushatak"
    www.yushatak.com

  2. #2
    Join Date
    Jan 2009
    Location
    Palm Springs CA
    Posts
    708
    Blog Entries
    19

    Default

    Quote Originally Posted by Raven View Post
    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...

  3. #3
    Join Date
    Mar 2010
    Location
    Florida, USA
    Posts
    1,944

    Default

    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 by Maverick1978; May 24th, 2010 at 01:21 PM.
    ---
    Currently seeking:
    * Roland MPU-401/AT (with daughter card header)
    * Magitronic K-156 Keyboard (5pin DIN w/ XT-AT switch)
    I also collect PC and C64 Sierra On-Line software!

  4. #4

    Default

    I think I wrote something in Turbo C back in the day to do what you need done. I also remember finding that someone had a better "echo", maybe "xecho" is it:

    ftp://ftp.simtel.net/pub/simtelnet/m...l/xecho133.zip.

    The date on the executable inside is from 1998. Sadly, as an external executable, it's going to slow things down, too, compared to the command.com built in.

    Jim

  5. #5

    Default

    Whee!

    @echo off
    for /f "usebackq delims=" %i in (`chkcpu /s`) do set mycpu=%i
    echo This machine is powered by an %mycpu%
    You're welcome.
    Apple ][+ through iMac i5, 5150 PC through dual Xeon W5580 and quad Itanium 9150M, and many in between.
    Newton, Palm V, N-Gage, Tapwave Zodiac, iPhone, iPhone 7.
    Intellivision, Game Boy through 3DS, Wii, XBone

  6. #6
    Join Date
    Jan 2007
    Location
    Pacific Northwest, USA
    Posts
    24,123
    Blog Entries
    20

    Default

    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)
    Attached Files Attached Files

  7. #7
    Join Date
    Dec 2005
    Location
    Toronto ON Canada
    Posts
    6,650

    Default

    Quote Originally Posted by Chuck(G) View Post
    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 by MikeS; May 24th, 2010 at 02:49 PM.

  8. #8

    Default

    Quote Originally Posted by Raven View Post
    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.

  9. #9

    Default

    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.
    Apple ][+ through iMac i5, 5150 PC through dual Xeon W5580 and quad Itanium 9150M, and many in between.
    Newton, Palm V, N-Gage, Tapwave Zodiac, iPhone, iPhone 7.
    Intellivision, Game Boy through 3DS, Wii, XBone

  10. #10
    Join Date
    Dec 2005
    Location
    Toronto ON Canada
    Posts
    6,650

    Default

    Quote Originally Posted by Anonymous Freak View Post
    Correction, I should have used double percents:
    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...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •