Redirected Output To HTML

May 12, 2009 at 20:31:20
Specs: Windows XP
I am redesigning an older batch script to redirect the output to HTML instead of text. I have converted most of the script, but have one section that is giving me problem.

My problem is how to redirect the output from the command below and add line breaks (returns) for each entry:

net share | FIND /V /I "The command completed successfully"

I have tried the following but it fails to produce the desired results:

net.exe share | FIND /V /I "The command completed successfully" ^<br^>

Some of my other queries look like the example below and they work fine, because they are only producing one-line outputs:

FOR /F "delims=" %%a in ('systeminfo 2^>nul^|FIND /I "Host Name:"') do echo %%a ^<br^>


TIA for any support


See More: Redirected Output To HTML

Report •


#1
May 13, 2009 at 01:55:34
Because your need the <br> at the end of each line you going to need to run all of the commands with multiple lines of output through a for /f loop.

for /f "delims=" %%a in ('net share^|FIND /V /I "The command completed successfully"') do (
echo %%a ^<br^> 
)

The other alternative it to use <pre> tags so that the line breaks will work without using <br>


Report •

#2
May 14, 2009 at 08:34:05
Thanks for the reply. I looked into using
 and decided to go that route.  The interesting thing about using 
 is that it preserves basic formatting, but adds an extra line between all the outputted entries, which is ok, because it helps with readability.  I had to add some span tags to adjust the font-size and alignment.   

I have tried unsuccessfully to add

 tags to the following code snippet.   Any suggestions?

for /f "tokens=*" %%a in ('fsutil fsinfo drives^|find /v ""') do (
set dr=%%a
call set driveList=%%driveList%% %%dr:~-3%%
)
for %%a in (%driveList%) do fsutil fsinfo drivetype %%a


TIA for any reply.


Report •

#3
May 14, 2009 at 15:13:44

The problem with fsutil is that it outputs in nonstandard formats. Sometimes you can utilize others just screw things up. For example "fsutil fsinfo drives" uses nul(hex 00) instead of spaces(hex 20), find interprets it as unicode text(in unicode ansi is accompanied with a second byte that is 00).

It also seems to output line brakes strangely, I have seen 0d0d0a and 0d20200d0a instead of plain old 0d0a.

Any way I have tried but failed, anyway I have to go to work now here's what I got up to:

@ECHO OFF
for /f "tokens=*" %%a in ('fsutil fsinfo drives^|find /v ""') do (
    set dr=%%a
    call set driveList=%%driveList%% "%%dr:~-3%%"
)

for %%a in (%driveList%) do @(
for /f "tokens=1,2,3*" %%b in ('fsutil fsinfo drivetype %%~a') do (
echo %%b %%c %%d Drive ^<br^>
)
)

Getting rid of the "drive" seems to get rid or the extra carrage return (0d).


Report •

Related Solutions

#4
May 15, 2009 at 08:36:34
For some reason, I keep getting double post. SORRY!

Report •

#5
May 15, 2009 at 13:05:34
Thanks for the code. I have tested it several times and it works perfectly!

THANKS!


Report •

#6
May 15, 2009 at 17:30:15
This is the last item that I am trying to fix. The code below output the requested information, but fails to separate the accounts. Any idea on how to add this separations between accounts?

FOR /F "skip=4 tokens=*" %%a IN ('net.exe user ^| FIND /V /I "The command completed successfully"') DO CALL :ParseUsers %%a
GOTO:EOF

:ParseUsers
FOR %%? IN (%*) DO CALL :ChkAcc %%?
GOTO:EOF

:: This is the section that does not produce the
:: desired separation.
:ChkAcc
FOR /F "tokens=* delims=" %%f IN ('net.exe user "%*" 2^>nul ^| FIND /V /I "The command completed successfully"') do (echo ^<pre^> %%f ^</pre^>)
GOTO:EOF


Report •

#7
May 15, 2009 at 18:06:32
Yep simply echo <br> a couple of times after each account. I also
changed the way the <pre> tags were entered because it looked
ugly in firefox, you can easily change it back:

@ECHO OFF
FOR /F "skip=4 delims=" %%a IN ('net.exe user ^| FIND /V /I "The command completed successfully"') DO CALL :ParseUsers %%a
goto :eof

:ParseUsers
FOR %%? IN (%*) DO CALL :ChkAcc %%?
GOTO:EOF

:: This is the section that does not produce the
:: desired separation.
:ChkAcc
echo ^<pre^>
FOR /F "delims=" %%f IN ('net.exe user "%*" 2^>nul ^| FIND /V /I "The command completed successfully"') do echo %%f
echo ^</pre^>
echo ^<br^>
echo ^<br^>
GOTO:EOF


Report •

#8
May 15, 2009 at 19:08:49
Thanks, I did not even think about trying to add an echo before the HTML code tags. The code works great. I need to do some research to fix the bug within this code that throws the error when an account name contain a space.

This account name works: myAccountName
This account name fails: my Account Name

In manual testing, I was able to fix it by wrapping the account name in " ".

Thanks again.


Report •

#9
May 15, 2009 at 19:40:33
I'm not sure it this will be any help to you or not;
it won't pick up any system accounts...

@ECHO OFF
for /f "skip=4 delims=" %%a in ('2^>nul reg query hku') do (
for /f "tokens=4* skip=4" %%b in ('2^>nul reg query "%%a\Software\Microsoft\Windows\CurrentVersion\Explorer" /v "logon user name"') do (
echo %%c
)
)

Edit:

I just realized this will only work to find the current user name, not all of them.............


Report •

#10
May 15, 2009 at 20:15:09
Within the code is there a method to encapsulate the account name variables with quotation marks?

Report •

#11
May 15, 2009 at 21:51:10
I had a look into it and it seems that the "net user" command is
more consistent than it first appears.

Windows only seems to allow account names that contain up to a
maximum of 20 characters, not allowing leading or trailing spaces.

The "net user" command displays the username padded to 20
characters with trailing spaces along with 5 additional
spaces to separate entries.

I was able to get it to work with spaces and ampersands,
it should presumably work with any other allowed characters.....

I was using a test account called "test & 2"

 
@ECHO OFF
for /f "skip=4 delims=" %%a in ('net user^|find /v /i "The command completed"') do (
	set line=%%a
	call :linesub
)
goto :eof

:linesub
if not defined line goto :eof
if "%line: =%"=="" goto :eof
set "uname=%line:~0,20%"
set "line=%line:~25%"
:depad
if "%uname:~-1%"==" " (
	set "uname=%uname:~0,-1%"
	goto depad
)
echo ^<pre^>
FOR /F "delims=" %%f IN ('net.exe user "%uname%" 2^>nul ^| FIND /V /I "The command completed successfully"') do echo %%f
echo ^</pre^>
echo ^<br^>
echo ^<br^>
GOTO linesub


Report •

#12
May 16, 2009 at 15:24:55
Thanks again. My old batch file has been GREATLY improved with your assistance!!

TODO items to finish:
1. basic error handling (if not exist, if errorlevel 1)
2. creation and destruction of %temp% files in %CD%

THANKS AGAIN.


Report •


Ask Question