Discussion:
I want a non-editing file display Window for script output.
(too old to reply)
John Stockton
2023-03-05 21:28:54 UTC
Permalink
I have scripts which generate (in %TEMP%) a plain-text file of batch code, and I want to read this file by eye, in a new plain Window, then manually copy'n'paste or drag'n'drop selected lines or contiguous groups of lines into a Command Prompt window, which will be ready and waiting. The lines all start "DEL" or "RD"; but must be thought about and selected before execution. I want to be UNABLE to alter the characters displayed, apart from by scrolling.

The batch command
START MSEDGE %1
does this, except that it does not work in Windows XP and that it opens a new tab rather than a new Window. In any case, EDGE is "a sledgehammer to crack a nut", and I don't want to have a window/tab which looks in the least like any browser that I have open.

So : is there an obscure but standard small part of Windows 10+ that can display a text file in a simple non-editable Window that supports Ctrl-C and vertical scroll? Notepad would do nicely, if it could be opened in a non-edit mode.

Can VBScript or JScript called from batch create such a Window _easily_?

Ideally, but certainly not essentially, I would like the displayed text to ge on a light-coloured background !
--
(c) John Stockton, near London, UK. Using Google Groups. |
Zaidy036
2023-03-05 22:33:57 UTC
Permalink
Post by John Stockton
I have scripts which generate (in %TEMP%) a plain-text file of batch code, and I want to read this file by eye, in a new plain Window, then manually copy'n'paste or drag'n'drop selected lines or contiguous groups of lines into a Command Prompt window, which will be ready and waiting. The lines all start "DEL" or "RD"; but must be thought about and selected before execution. I want to be UNABLE to alter the characters displayed, apart from by scrolling.
The batch command
START MSEDGE %1
does this, except that it does not work in Windows XP and that it opens a new tab rather than a new Window. In any case, EDGE is "a sledgehammer to crack a nut", and I don't want to have a window/tab which looks in the least like any browser that I have open.
So : is there an obscure but standard small part of Windows 10+ that can display a text file in a simple non-editable Window that supports Ctrl-C and vertical scroll? Notepad would do nicely, if it could be opened in a non-edit mode.
Can VBScript or JScript called from batch create such a Window _easily_?
Ideally, but certainly not essentially, I would like the displayed text to ge on a light-coloured background !
COLOR XX & TYPE <full path>
John Stockton
2023-03-06 12:02:49 UTC
Permalink
Post by Zaidy036
Post by John Stockton
I have scripts which generate (in %TEMP%) a plain-text file of batch code, and I want to read this file by eye, in a new plain Window, then manually copy'n'paste or drag'n'drop selected lines or contiguous groups of lines into a Command Prompt window, which will be ready and waiting. The lines all start "DEL" or "RD"; but must be thought about and selected before execution. I want to be UNABLE to alter the characters displayed, apart from by scrolling.
The batch command
START MSEDGE %1
does this, except that it does not work in Windows XP and that it opens a new tab rather than a new Window. In any case, EDGE is "a sledgehammer to crack a nut", and I don't want to have a window/tab which looks in the least like any browser that I have open.
So : is there an obscure but standard small part of Windows 10+ that can display a text file in a simple non-editable Window that supports Ctrl-C and vertical scroll? Notepad would do nicely, if it could be opened in a non-edit mode.
Can VBScript or JScript called from batch create such a Window _easily_?
Ideally, but certainly not essentially, I would like the displayed text to be on a light-coloured background !
COLOR XX & TYPE <full path>
I wasn't sufficiently aware of COLOR (and it might nowadays be illegal of Microsoft to have failed to implement, as an alternative, the correct spelling "COLOUR") - thanks for that. It would be nice to have a modification which applies the new colour only to subsequent lines.

I would want to use a different Command Prompt window to receive the copied selected lines; but START CMD will open one, of usefully different visual styling.

I need to test the idea out, to see whether the chief user (me) likes it in operation.
--
(c) John Stockton, near London, UK. Using Google Groups. |
Zaidy036
2023-03-06 19:09:11 UTC
Permalink
Post by John Stockton
Post by Zaidy036
Post by John Stockton
I have scripts which generate (in %TEMP%) a plain-text file of batch code, and I want to read this file by eye, in a new plain Window, then manually copy'n'paste or drag'n'drop selected lines or contiguous groups of lines into a Command Prompt window, which will be ready and waiting. The lines all start "DEL" or "RD"; but must be thought about and selected before execution. I want to be UNABLE to alter the characters displayed, apart from by scrolling.
The batch command
START MSEDGE %1
does this, except that it does not work in Windows XP and that it opens a new tab rather than a new Window. In any case, EDGE is "a sledgehammer to crack a nut", and I don't want to have a window/tab which looks in the least like any browser that I have open.
So : is there an obscure but standard small part of Windows 10+ that can display a text file in a simple non-editable Window that supports Ctrl-C and vertical scroll? Notepad would do nicely, if it could be opened in a non-edit mode.
Can VBScript or JScript called from batch create such a Window _easily_?
Ideally, but certainly not essentially, I would like the displayed text to be on a light-coloured background !
COLOR XX & TYPE <full path>
I wasn't sufficiently aware of COLOR (and it might nowadays be illegal of Microsoft to have failed to implement, as an alternative, the correct spelling "COLOUR") - thanks for that. It would be nice to have a modification which applies the new colour only to subsequent lines.
I would want to use a different Command Prompt window to receive the copied selected lines; but START CMD will open one, of usefully different visual styling.
I need to test the idea out, to see whether the chief user (me) likes it in operation.
Following batch changes font color but not the background color:

:: _Color.bat

:: %1 is color [R]ed, [G]reen, [Y]ellow, or [W]hite
:: %2 is text to be typed and if contains spaces requires "..."

:: Examples
:: CALL _Color.bat R RED
:: CALL _Color.bat G "GREEN GREEN GREEN"

ECHO OFF

IF "%1"=="R" ECHO ^%~2
IF "%1"=="G" ECHO ^%~2
IF "%1"=="Y" ECHO ^%~2
IF "%1"=="B" ECHO ^%~2
IF "%1"=="M" ECHO ^%~2
IF "%1"=="C" ECHO ^%~2
IF "%1"=="W" ECHO ^%~2
IF "%1"=="BR" ECHO ^^%~2
IF "%1"=="MR" ECHO ^^%~2
Robert Roland
2023-03-06 09:56:08 UTC
Permalink
On Sun, 5 Mar 2023 13:28:54 -0800 (PST), John Stockton
Post by John Stockton
is there an obscure but standard small part of Windows 10+ that can display a text file in a simple non-editable Window that supports Ctrl-C and vertical scroll?
How about PowerShell's Out-GridView?

powershell -command "Get-Content -Path %1|Out-GridView -Wait"

It can also be used to allow the user to select items and then return
the selected items:

powershell -command "Get-Content -Path %1|Out-GridView -OutputMode
Multiple"
--
RoRo
John Stockton
2023-03-06 13:11:24 UTC
Permalink
Post by Robert Roland
On Sun, 5 Mar 2023 13:28:54 -0800 (PST), John Stockton
Post by John Stockton
is there an obscure but standard small part of Windows 10+ that can display a text file in a simple non-editable Window that supports Ctrl-C and vertical scroll?
How about PowerShell's Out-GridView?
powershell -command "Get-Content -Path %1|Out-GridView -Wait"
It can also be used to allow the user to select items and then return
powershell -command "Get-Content -Path %1|Out-GridView -OutputMode
Multiple"
--
RoRo
Interesting - I know little of PowerShell.

I have just executed
Prompt>powershell /?
and therefore
Prompt>powershell /? > POWRSHEL.TXT
!

Your second example does what I want, except that the selected lines are shown (in a rather small font) but not executed. A simple copy'n'paste seems to fix the latter.

I need to find Powershell and Out-GridView reference material.

Thanks.
--
(c) John Stockton, near London, UK. Using Google Groups. |
Robert Roland
2023-03-06 19:51:29 UTC
Permalink
On Mon, 6 Mar 2023 05:11:24 -0800 (PST), John Stockton
Post by John Stockton
Interesting - I know little of PowerShell.
It is a bit of a learning curve at first, but it is well worth the
effort.
Post by John Stockton
Your second example does what I want, except that the selected lines are shown (in a rather small font) but not executed. A simple copy'n'paste seems to fix the latter.
Unless I have misunderstood, that is exaxtly what you asked for.

As far is I know, there is no way to change the font size. I think it
might be inherited from Windows' general settings.

Since your text files contains both commands and file names, it gets
quite fiddly. The fact that RD and DEL are both internal commands does
not help.

If you could change your script so that the text file contains only
file names, simply pipe the result into Remove-Item:

powershell -command "Get-Content -Path %1|Out-GridView -OutputMode
Multiple|Remove-Item -WhatIf"

The "-WhatIf" causes the Remove-Item cmdlet to not do anything other
than saying what it would have done. Remove when you are ready to test
for real.

You can also add a title to the grid view if you want:

powershell -command "Get-Content -Path %1|Out-GridView -OutputMode
Multiple -Title 'Select files to delete:'|Remove-Item -WhatIf"
Post by John Stockton
I need to find Powershell and Out-GridView reference material.
In a PowerShell prompt, simply enter:

Get-Help -Name Out-GridView -Full
--
RoRo
JJ
2023-03-07 05:23:53 UTC
Permalink
Post by John Stockton
So : is there an obscure but standard small part of Windows 10+ that can
display a text file in a simple non-editable Window that supports Ctrl-C
and vertical scroll? Notepad would do nicely, if it could be opened in a
non-edit mode.
You can use HTML Application (mshta.exe).
Post by John Stockton
Can VBScript or JScript called from batch create such a Window _easily_?
If you meant VBScript/JScript code, then no. Because thowe code may contain
batch file's special characters. Any of those special characters may need to
be quoted and/or escaped.
Post by John Stockton
Ideally, but certainly not essentially, I would like the displayed text
to ge on a light-coloured background !
This is using HTA with JScript.

@echo off
setlocal
rem pass a text file's name as batch file argument
if "%~1" == "" goto :eof
set "tf=%temp%\viewer.hta"
set "fn=%~f1"
Post by John Stockton
"%tf%" (
echo ^<title^>%fn%^</title^>^<style^>
echo body{margin:0;height:100%%;overflow:hidden}
echo #t{border:0;padding:.2em .4em;width:100%%;height:100%%}
echo ^</style^>^<textarea id=t readonly^>^</textarea^>^<script^>
echo t.innerText=(new ActiveXObject('scripting.filesystemobject'
echo ^)^).openTextFile('%fn:\=\\%'^).readAll(^)
echo ^</script^>
)
start /wait mshta.exe "%tf%"
del "%tf%"

As you can see, the `<`, `>`, `)`, and literal `%` characters in both the
JScript and HTML code, are escaped since they're part of batch file's
special characters.

The `)` doesn't actually need to be escaped if the character is not within
batch file's command group (which uses parentheses). But the `)` in that
code is within a command group.

The above batch file uses temporary file for the .hta file. Without using
any temporary file is possible, but the whole HTML code must be specified in
MSHTA's command line as one line - which can be quite long. e.g.

@echo off
setlocal
rem pass a text file's name as batch file argument
if "%~1" == "" goto :eof
set "fn=%~f1"
start /wait mshta.exe "javascript:'<title>%fn:\=\\%</title><style>body{margin:0;height:100%%;overflow:hidden}#t{border:0;padding:.2em .4em;width:100%%;height:100%%}</style><textarea id=t readonly></textarea><script>t.innerText=(new ActiveXObject(\'scripting.filesystemobject\')).openTextFile(document.title).readAll()</script>'"

The `<`, `>`, and `)` characters in above code doesn't need to be escaped,
because they're already wrapped in double-quotes. However, the literal `%`
characters still need to be escaped.

The `'` (single-quote) and `\` characters need to be escaped for the JScript
code's context - which I think you already know why, since you're
occasionally dwells in comp.lang.javascript.


MSHTA is the most direct way to excute VBScript/JScript code. Windows Script
Host (WSH/wscript.exe/cscript.exe) requires a file to execute
VBScript/JScript code. MSHTA JScript e.g.:

mshta.exe "javascript:alert('hello world')"

Loading...