Ad
Cut Off Text Instead Of Going Into A New Line - Batch
I am trying to display cmdtext.txt in a batch file. I want it to just cut off (just as shown below) when there is no space left instead of going into a new line, because it ruins the "style" and the actual purpose of this file. (The batch file runs maximized, so the text would have enough space to display)
________/\\\\\\\\\__/\\\\____________/\\\\__/\\\\\\\\\\\\___________________/\\\\\\\\\\\\\\\______________________________/\\\\\\___________________________________________________________________________________________________________________________________________
______/\\\////////__\/\\\\\\________/\\\\\\_\/\\\////////\\\________________\///////\\\/////______________________________\////\\\__________________________________________________________________________________________________________________________________________
_____/\\\/___________\/\\\//\\\____/\\\//\\\_\/\\\______\//\\\_____________________\/\\\______________________________________\/\\\_________________________________________________________________________________________________________________________________________
_____/\\\_____________\/\\\\///\\\/\\\/_\/\\\_\/\\\_______\/\\\__/\\\\\\\\\\\_______\/\\\___________/\\\\\________/\\\\\_______\/\\\_____/\\\\\\\\\\________________________________________________________________________________________________________________________
_____\/\\\_____________\/\\\__\///\\\/___\/\\\_\/\\\_______\/\\\_\///////////________\/\\\_________/\\\///\\\____/\\\///\\\_____\/\\\____\/\\\//////________________________________________________________________________________________________________________________
______\//\\\____________\/\\\____\///_____\/\\\_\/\\\_______\/\\\_____________________\/\\\________/\\\__\//\\\__/\\\__\//\\\____\/\\\____\/\\\\\\\\\\______________________________________________________________________________________________________________________
________\///\\\__________\/\\\_____________\/\\\_\/\\\_______/\\\______________________\/\\\_______\//\\\__/\\\__\//\\\__/\\\_____\/\\\____\////////\\\_____________________________________________________________________________________________________________________
___________\////\\\\\\\\\_\/\\\_____________\/\\\_\/\\\\\\\\\\\\/_______________________\/\\\________\///\\\\\/____\///\\\\\/____/\\\\\\\\\__/\\\\\\\\\\____________________________________________________________________________________________________________________
_______________\/////////__\///______________\///__\////////////_________________________\///___________\/////________\/////_____\/////////__\//////////____________________________________________________________________________________________________________________
Ad
Answer
Batch has no builtins for tasks like this. When you wish to format or restrict output, you need to consider what steps you need to take to achieve the goal.
First, consider what information you need. In this task, you need:
- The width of the console in columns
- Acquire this by iterating over the mode command with a for /f loop
- The data to format
Next, For the purpose of restricting output to the consoles width, Substing modification can be used to trim the data you are formatting to the consoles width:
@Echo off
Call:Header
Set /A Y=lines,X=columns
Timeout /t 2 /NoBreak
mode 90,30
Call:Header
Timeout /t 2 /NoBreak
mode %X%,%Y%
Goto:Eof
:Header
(Set LF=^
%= Empty lines above required =%)
Setlocal EnableDelayedExpansion
For /f "tokens=1,2 Delims=: " %%G in ('mode ^| findstr /li "col lin"')Do Set "$%%G=%%H"
Set "Output="
For /f "usebackq tokens=1 delims=:1;" %%G in (`type "%~f0" ^| %SystemRoot%\System32\findstr.exe /blc:":1;" "%~f0"`) Do (
Set "Line=%%G"
Set "Output=!Output!!Line:~0,%$Columns%!!LF!"
)
Echo(!Output!
For /f "tokens=1,2 Delims=;" %%G in ("lines=!$lines!;Columns=!$Columns!")Do Endlocal & (
Set "%%G"
Set "%%H"
)
Exit /b
:1;________/\\\\\\\\\__/\\\\____________/\\\\__/\\\\\\\\\\\\___________________/\\\\\\\\\\\\\\\______________________________/\\\\\\___________________________________________________________________________________________________________________________________________
:1;______/\\\////////__\/\\\\\\________/\\\\\\_\/\\\////////\\\________________\///////\\\/////______________________________\////\\\__________________________________________________________________________________________________________________________________________
:1;_____/\\\/___________\/\\\//\\\____/\\\//\\\_\/\\\______\//\\\_____________________\/\\\______________________________________\/\\\_________________________________________________________________________________________________________________________________________
:1;_____/\\\_____________\/\\\\///\\\/\\\/_\/\\\_\/\\\_______\/\\\__/\\\\\\\\\\\_______\/\\\___________/\\\\\________/\\\\\_______\/\\\_____/\\\\\\\\\\________________________________________________________________________________________________________________________
:1;_____\/\\\_____________\/\\\__\///\\\/___\/\\\_\/\\\_______\/\\\_\///////////________\/\\\_________/\\\///\\\____/\\\///\\\_____\/\\\____\/\\\//////________________________________________________________________________________________________________________________
:1;______\//\\\____________\/\\\____\///_____\/\\\_\/\\\_______\/\\\_____________________\/\\\________/\\\__\//\\\__/\\\__\//\\\____\/\\\____\/\\\\\\\\\\______________________________________________________________________________________________________________________
:1;________\///\\\__________\/\\\_____________\/\\\_\/\\\_______/\\\______________________\/\\\_______\//\\\__/\\\__\//\\\__/\\\_____\/\\\____\////////\\\_____________________________________________________________________________________________________________________
:1;___________\////\\\\\\\\\_\/\\\_____________\/\\\_\/\\\\\\\\\\\\/_______________________\/\\\________\///\\\\\/____\///\\\\\/____/\\\\\\\\\__/\\\\\\\\\\____________________________________________________________________________________________________________________
:1;_______________\/////////__\///______________\///__\////////////_________________________\///___________\/////________\/////_____\/////////__\//////////____________________________________________________________________________________________________________________
Ad
source: stackoverflow.com
Related Questions
- → how can I debug exe with soem switch flags from command prompt
- → How to get an Batch file .bat continue onto the next statement if there is an error
- → Automated script to zip IIS logs?
- → batch - how can I close a batch file that was started from another batch file
- → Batch closes prematurely on a for /f command
- → Run Python script out of python script via .bat
- → Portable python script in Windows
- → unable to run python script from Batch file
- → How do I open an Access database (and wait for it to close before proceeding) in a batch file?
- → Permanently altering a user's %PATH% environment variable via batch or Python
- → wrapper for git, for jenkins pipeline, on windows 10 jenkins slave
- → bat file to issue a git pull command and leave the git bash window open
- → Forfiles command in For Loop
Ad