Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

I want a non-editing file display Window for script output.

19 views
Skip to first unread message

John Stockton

unread,
Mar 5, 2023, 4:28:55 PM3/5/23
to

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

unread,
Mar 5, 2023, 5:34:01 PM3/5/23
to
COLOR XX & TYPE <full path>

Robert Roland

unread,
Mar 6, 2023, 4:56:04 AM3/6/23
to
On Sun, 5 Mar 2023 13:28:54 -0800 (PST), John Stockton
<dr.j.r....@gmail.com> wrote:

>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

unread,
Mar 6, 2023, 7:02:50 AM3/6/23
to
> > 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.

John Stockton

unread,
Mar 6, 2023, 8:11:26 AM3/6/23
to
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.

Zaidy036

unread,
Mar 6, 2023, 2:09:14 PM3/6/23
to
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 ^ [91m%~2 [0m
IF "%1"=="G" ECHO ^ [92m%~2 [0m
IF "%1"=="Y" ECHO ^ [93m%~2 [0m
IF "%1"=="B" ECHO ^ [94m%~2 [0m
IF "%1"=="M" ECHO ^ [95m%~2 [0m
IF "%1"=="C" ECHO ^ [96m%~2 [0m
IF "%1"=="W" ECHO ^ [97m%~2 [0m
IF "%1"=="BR" ECHO ^ [1m^ [91m%~2 [0m
IF "%1"=="MR" ECHO ^ [1m^ [95m%~2 [0m

Robert Roland

unread,
Mar 6, 2023, 2:51:24 PM3/6/23
to
On Mon, 6 Mar 2023 05:11:24 -0800 (PST), John Stockton
<dr.j.r....@gmail.com> wrote:

>Interesting - I know little of PowerShell.

It is a bit of a learning curve at first, but it is well worth the
effort.

>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"

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

In a PowerShell prompt, simply enter:

Get-Help -Name Out-GridView -Full
--
RoRo

JJ

unread,
Mar 7, 2023, 12:23:57 AM3/7/23
to
On Sun, 5 Mar 2023 13:28:54 -0800 (PST), John Stockton wrote:
>
> 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).

> 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.

> 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"
>"%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')"
0 new messages