Saved Bookmarks
| 1. |
Solve : deleting space from result? |
|
Answer» 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. Simple answer: Just do not take a number from a file. I know that. Thing is I want to learn how to do itBlisk, 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? 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? 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. 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=TIMEOUT /T %out%Try chcp 850 instead. Did you change font to Lucida Console? 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?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. 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 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. 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 thatYour 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. Yes this works now, thank you. TYPE number.txt > number1.txt set /p out=timeout /T %out% I created number file with this powershell 1| % {Get-Random -Minimum 2 -Maximum 222 } | Out-File -FilePath D:\number.txt |
|