Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: deleting space from result  (Read 6352 times)

0 Members and 1 Guest are viewing this topic.

Blisk

    Topic Starter


    Intermediate

    Thanked: 1
    • Experience: Familiar
    • OS: Windows 7
    deleting space from result
    « on: April 06, 2019, 04:24:11 PM »
    I have tested a little script to take a number from txt file and use it in batch, but problem is I get that litle square and script doesnt work.
    How to get just a number so script will work. In file d:\number.txt is only a number for timeout delay

    Code: [Select]
    set /p out=<d:\number.txt
    TIMEOUT /T %out%

    and this is what I get

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: deleting space from result
    « Reply #1 on: April 06, 2019, 06:24:34 PM »
    Simple answer: Just do not take a number from a file.
    Put the number in the batch file itself.
    Why is that hard to do?


    Blisk

      Topic Starter


      Intermediate

      Thanked: 1
      • Experience: Familiar
      • OS: Windows 7
      Re: deleting space from result
      « Reply #2 on: April 07, 2019, 12:11:05 AM »
      Simple answer: Just do not take a number from a file.
      Put the number in the batch file itself.
      Why is that hard to do?

      I know that.
      Thing is I want to learn how to do it

      Salmon Trout

      • Guest
      Re: deleting space from result
      « Reply #3 on: April 07, 2019, 02:33:45 AM »
      Blisk, how is the file number.txt made? What is that leading character before the '4'? It is not just a simple space; the timeout command doesn't mind spaces before the number.

      Why is the number being got from a file?



      « Last Edit: April 07, 2019, 03:19:36 AM by Salmon Trout »

      Salmon Trout

      • Guest
      Re: deleting space from result
      « Reply #4 on: April 07, 2019, 04:41:04 AM »
      You can get exactly this problem if number.txt has Unicode encoding. If you are creating the text in Notepad or some other editor, save with ANSI encoding.

      If you doing it that way (with an editor), why?



      « Last Edit: April 07, 2019, 05:03:17 AM by Salmon Trout »

      Salmon Trout

      • Guest
      Re: deleting space from result
      « Reply #5 on: April 07, 2019, 05:15:07 AM »
      Alternative:

      Do 1 and 2 and maybe also 3

      1. Save text with UTF-8 encoding.

      2. Add this line at the top of your batch file underneath @echo off

      chcp 65001 >nul

      3. As well as these things, also try a Unicode font for console such as Lucida Console.




      Blisk

        Topic Starter


        Intermediate

        Thanked: 1
        • Experience: Familiar
        • OS: Windows 7
        Re: deleting space from result
        « Reply #6 on: April 07, 2019, 08:55:16 AM »
        I have created file with batch
        copy /y nul d:\number.txt
        echo 5 >> d:\number.txt

        This also didn't help
        @echo off
        chcp 65001 >nul
        also if I save number.txt with UTF8 or ANSI, I get the same result.

        What is than right way to do that?

        So this is whole script now. and doesn't work
        @echo off
        chcp 65001 >nul
        echo 5 > d:\number.txt
        set /p out=<d:\number.txt
        TIMEOUT /T %out%

        Salmon Trout

        • Guest
        Re: deleting space from result
        « Reply #7 on: April 07, 2019, 09:17:04 AM »
        Try chcp 850 instead.


        Salmon Trout

        • Guest
        Re: deleting space from result
        « Reply #8 on: April 07, 2019, 09:31:40 AM »
        Did you change font to Lucida Console?

        Blisk

          Topic Starter


          Intermediate

          Thanked: 1
          • Experience: Familiar
          • OS: Windows 7
          Re: deleting space from result
          « Reply #9 on: April 07, 2019, 09:42:06 AM »
          When I edit with notepad and add chcp 850 in batch it works
          but when I generate number.txt with powershell it doesn't work
          Is there more celan way to do this like ignore first charter?

          Sidewinder



            Guru

            Thanked: 139
          • Experience: Familiar
          • OS: Windows 10
          Re: deleting space from result
          « Reply #10 on: April 07, 2019, 09:49:59 AM »
          Not to *censored* in but: I suspect it sees the 5 as a stream number as in 2>nul. Try escaping the 5, echo ^5 > d:\number.txt

          Just a thought. 8)
          The true sign of intelligence is not knowledge but imagination.

          -- Albert Einstein

          Salmon Trout

          • Guest
          Re: deleting space from result
          « Reply #11 on: April 07, 2019, 11:28:04 AM »
          To avoid the stream number thing, you need a space after the number, before the > symbol.

          See here, the first try leaves number.txt blank

          C:\>echo 5> number.txt
          ECHO is on.

          C:\>type number.txt

          C:\>dir number.txt

          07/04/2019  18:20                 0 number.txt

          C:\>echo 5 > number.txt

          C:\>type number.txt
          5


          Quote from: Blisk
          when I generate number.txt with powershell it doesn't work

          Why Powershell?

          Quote from: Blisk
          copy /y nul d:\number.txt
          echo 5 >> d:\number.txt

          Why are you doing this?????

          This works every time for me....

          C:\>echo 5 > d:\number.txt

          C:\>set /p out=<d:\number.txt

          C:\>timeout /T %out%

          Waiting for 0 seconds, press a key to continue ...

          C:\>chcp
          Active code page: 850


          Timeout waits correctly for 5 seconds, no CHCP change needed.






          Blisk

            Topic Starter


            Intermediate

            Thanked: 1
            • Experience: Familiar
            • OS: Windows 7
            Re: deleting space from result
            « Reply #12 on: April 07, 2019, 11:48:35 AM »
            I am trying to learn some stuff which doesn't work.
            Can you please try with my file, which doesn't work with me.

            When I put in quotes I see there are tvo charters before number!
            Somehov I should skip that
            « Last Edit: April 07, 2019, 12:38:06 PM by Blisk »

            Salmon Trout

            • Guest
            Re: deleting space from result
            « Reply #13 on: April 07, 2019, 12:46:20 PM »
            Your file says 148, and it is encoded as Unicode. How did you make it?

            Anyhow, convert Unicode to ANSI with the TYPE command:

            TYPE number.txt > number.txt

            It works, I just tried it.





            Blisk

              Topic Starter


              Intermediate

              Thanked: 1
              • Experience: Familiar
              • OS: Windows 7
              Re: deleting space from result
              « Reply #14 on: April 07, 2019, 12:56:12 PM »
              Yes this works now, thank you.
              TYPE number.txt > number1.txt
              set /p out=<d:\number1.txt
              timeout /T %out%

              I created number file with this powershell
              1| % {Get-Random -Minimum 2 -Maximum 222 } | Out-File -FilePath D:\number.txt