Announcement

Collapse
No announcement yet.

Use OS built in command line CLS to insert a Form Feed character to file or to STDOUT

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Use OS built in command line CLS to insert a Form Feed character to file or to STDOUT

    I really thought of putting this somewhere else in the forum but i wanted any other person that did not know this to be aware of it.

    I just found this out 2 months ago when I need to put a form feed into some files to separate report pages.in batch file out to stdout to files.
    I really did not know that all CLS does is send a form feed character to the console or stdout out really.
    CLS > OUTPUT.TXT
    or
    what i am really using is this
    CLS >>OUTPUT.TXT
    or
    CLS > LPT1

    The form feed characters are very easily to remove from the begging of files, multiple joined form feed characters joined together and any
    at the end of a file.
    I will write a simple program that does that bit of clean up and post it.
    You have no idea how hard i worked to get those form feeds easily into places I needed them and only to find out that it was so simple place.
    Now how about a linefeed character? Anybody?
    p purvis

  • #2
    Code:
    echo Hi Paul > OUTPUT.TXT
    echo. >> OUTPUT.TXT
    echo I think I found it! >> OUTPUT.TXT
    ... .... . ... . . ... ... .... . .. ... .... .. ... .... .. .... ..

    n6jah @ yahoo.com

    Comment


    • #3
      Jim that adds a line feed alright along with some "lagniappe".
      p purvis

      Comment


      • #4
        Jim I tried the echo. with a dot added on with at space and it does create a single space with added carriage return and line feed.
        Have been putting a space then a period in some of my batch files to provide spacing of lines and it will be much nicer now without the periods.
        So using the ECHO plus a single period with no spaces works for adding lines but getting the spaces. I bet there is hidden
        p purvis

        Comment


        • #5
          create a new file or delete a file and create a new file of zero length
          Code:
          break > output.txt
          dir output.txt
          11/07/2018  12:27 PM                 0 output.txt
          p purvis

          Comment


          • #6
            With no space after the period, we get an empty line with no extra stuff.

            Code:
            echo Hi Paul. > OUTPUT.TXT
            echo.>> OUTPUT.TXT
            echo Yep, we found it! >> OUTPUT.TXT
            And I don't recall ever seeing the word "lagniappe" Wow! Thanks for the lesson.


            ... .... . ... . . ... ... .... . .. ... .... .. ... .... .. .... ..

            n6jah @ yahoo.com

            Comment


            • #7
              That is EXCELLENT.
              I had found a webpage where they listed a few other characters along with period character and I need to find that and post that source.
              Who would of ever thought about not having a space after the period. I did not see the use of putting redirection characters immediately behind the command.

              In testing other builtin commands for the console when trying find the solution to getting the unwanted space character before the CRLF. I found redirection of some other commands like using BREAK >> Output.txt generated a file of zero length too but I did not really see one that I would like to use other than BREAK and in my haste of trying to produce your EXCELLENT find, I am not so sure I covered all possible builtin console commands.
              Having SSD drives, a file length of zero length made me question myself about how that might affect blocks on a SSD drive. Of course it would add to space where the file index of the drive is kept.
              i have had a personal dislike of zero length files in the past mostly because some backup routines did not keep them. I think Gary had that problem recently too.
              From the MSDOS days, I learned to keep from having unallocated file cluster problems, that for me when creating a new file or writing over another. It was best to create the file then, close it, then reopen the same file and write to file basically adding to the file. CP/M and MP/M did not have that problem because the file allocation table was updated after either a full hart drive sector or partial filled(last characters wriiten usually) hard drive sector was written. This is one reason MSDOS was much faster in that it did not update the file allocation table as many times as CP/M and MP/M when adding to the length of a file.
              p purvis

              Comment


              • #8
                Program to make changes of the string "ECHO ." to "ECHO." in only ascii batch files.
                The os console command "ECHO................................." will not produce an empty line feed but a line of dots.
                This program will not make any changes unless an command tail option of "/MAKECHANGES" is used.for safety reasons and reporting of files that would have been changed.

                Code:
                'batchfilecompressechodot.bas
                'compiled with pbcc 4.04
                'program makes attempts to change in batch files where the  string "echo ." exist.
                'by using period immediate after the os command ECHO in a batch file can create a linefeed
                ' unless other characters follow the period as tested in microsoft windows 7 pro
                'this program makes use of an command tail option to force the changes to be written to disk
                '   others, this program will basically only ilist files it would of changed.
                'this program only searches echo with a space
                '
                #COMPILE EXE
                #DIM ALL
                #BREAK ON
                
                
                GLOBAL iwritechangestofiles AS LONG
                
                FUNCTION replaceechodot(BYREF sfilename AS STRING) AS LONG
                    LOCAL ifileno AS LONG
                    LOCAL scontents AS STRING
                    LOCAL stemp AS STRING
                
                    IF UCASE$(RIGHT$(sfilename,4))<>".BAT" THEN EXIT FUNCTION
                    IF NOT ISFILE(sfilename) THEN EXIT FUNCTION
                
                
                    ifileno=FREEFILE
                    TRY
                    OPEN sfilename FOR BINARY ACCESS READ WRITE LOCK SHARED AS ifileno LEN=32767
                    CATCH
                    CLOSE
                    EXIT FUNCTION
                    EXIT TRY
                    FINALLY
                    END TRY
                    GET$ #ifileno, LOF(ifileno), scontents
                    CLOSE
                
                    IF INSTR(UCASE$(scontents),"ECHO .")=0& THEN
                        EXIT FUNCTION
                    END IF
                
                    STDOUT "found echo . in "+sfilename
                    WHILE INSTR(scontents,"ECHO .")
                        REPLACE "ECHO ." WITH "ECHO." IN scontents
                    WEND
                    WHILE INSTR(scontents,"Echo .")
                        REPLACE "Echo ." WITH "ECHO." IN scontents
                    WEND
                    WHILE INSTR(scontents,"echo .")
                        REPLACE "echo ." WITH "ECHO." IN scontents
                    WEND
                    IF INSTR(UCASE$(scontents),"ECHO .") THEN
                       STDOUT sfilename+"file still contains -echo .- in the file, aborting changes."
                       EXIT FUNCTION
                    END IF
                
                    'test where the program might not of caught all echo . strings
                    'if any exist, just report it to stdout and do not make changes
                    stemp=UCASE$(TRIM$(scontents))
                    WHILE INSTR(stemp,$SPC+$SPC)
                        REPLACE $SPC+$SPC WITH $SPC IN stemp
                    WEND
                    IF INSTR(stemp,"ECHO .") THEN
                       STDOUT sfilename+" file still contains -echo .- in a unknow format, aborting changes."
                       EXIT FUNCTION
                    END IF
                
                    IF iwritechangestofiles=0& THEN
                        STDOUT sfilename+" would of changed if option /makechanges activated."
                        EXIT FUNCTION
                    END IF
                    KILL sfilename
                    STDOUT "changes made and written to "+sfilename
                    OPEN sfilename FOR BINARY ACCESS READ WRITE LOCK SHARED AS ifileno LEN=32767
                    PUT$ ifileno, scontents
                    CLOSE ifileno
                END FUNCTION
                
                
                FUNCTION processallbatchfilesindirectory(BYREF sdirectory AS STRING) AS LONG
                    LOCAL sfilename AS STRING
                    CHDIR sdirectory
                    STDOUT "procesing directory "+sdirectory
                    sfilename = DIR$("*.BAT")
                    WHILE LEN(sfilename)
                        IF ISFILE(sfilename) THEN replaceechodot(sfilename)
                        sfilename = DIR$(NEXT)
                    WEND
                END FUNCTION
                
                
                
                
                FUNCTION PBMAIN () AS LONG
                    LOCAL scommandline AS STRING
                    LOCAL scurrentdrive AS STRING
                    LOCAL sfullcurrentfolder AS STRING
                    LOCAL xlocation AS LONG
                
                
                    scommandline=" "+TRIM$(COMMAND$)+" "
                
                    WHILE INSTR(UCASE$(scommandline)," /MAKECHANGES ")
                        xlocation=INSTR(UCASE$(scommandline)," /MAKECHANGES ")
                        iwritechangestofiles=1&
                        scommandline=LEFT$(scommandline,xlocation)+RIGHT$(scommandline,LEN(scommandline)-(xlocation+12&))
                    WEND
                    scommandline=TRIM$(scommandline)
                    IF LEN(SCOMMANDLINE)>4 THEN
                        IF RIGHT$(UCASE$(scommandline),4)=".BAT" THEN
                            replaceechodot(scommandline)
                            EXIT FUNCTION
                        END IF
                    END IF
                
                    IF ISFOLDER(scommandline) AND INSTR(scommandline,"?")=0& THEN
                        sfullcurrentfolder = CURDIR$
                        IF MID$(CURDIR$,2,1) = ":" THEN
                           scurrentdrive = LEFT$(CURDIR$,2)
                           IF INSTR(" A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ",$SPC+UCASE$(scurrentdrive)+$SPC)=0& THEN scurrentdrive=""
                        END IF
                        processallbatchfilesindirectory(scommandline)
                        IF LEN(scurrentdrive) THEN CHDRIVE scurrentdrive
                        IF LEN(sfullcurrentfolder) THEN CHDIR sfullcurrentfolder
                        EXIT FUNCTION
                     END IF
                
                    STDOUT "Program replaces echo ., that is echo followed by a dot with ECHO."
                    STDOUT "The purpose of ECHO. is to create a blank line in batch file output."
                    STDOUT "Insert a file name file or directory name on the command line."
                    STDOUT "This program does not preform directory recursive but works"
                    STDOUT " with a single directory and only processes files ending"
                    STDOUT " with a .bat extension and does not work on unicode files either."
                    STDOUT "Either put in a single single file or a directory where batch files are."
                    STDOUT "If this program is not able to make changes all strings of echo . to ECHO."
                    STDOUT " in the batch file, then it will not make any changes to the file."
                    STDOUT "The user agrees to assumes all responsiblity for running this program."
                    STDOUT "It is up the user to make backup of files before running this program."
                    STDOUT "You have to use a command tail option /makechanges to write the changes."
                    STDOUT "Only valid case matches of ECHO . are  ECHO ., Echo ., and echo . "
                
                END FUNCTION
                Attached Files
                p purvis

                Comment

                Working...
                X