Computing.Net > Forums > Programming > Redirected Output To HTML

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Redirected Output To HTML

Reply to Message Icon

Name: needToCode
Date: May 12, 2009 at 20:31:20 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Judago
Date: May 13, 2009 at 01:55:34 Pacific
Reply:

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>


0

Response Number 2
Name: needToCode
Date: May 14, 2009 at 08:34:05 Pacific
Reply:

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.


0

Response Number 3
Name: Judago
Date: May 14, 2009 at 15:13:44 Pacific
Reply:

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


0

Response Number 4
Name: needToCode
Date: May 15, 2009 at 08:36:34 Pacific
Reply:

For some reason, I keep getting double post. SORRY!


0

Response Number 5
Name: needToCode
Date: May 15, 2009 at 13:05:34 Pacific
Reply:

Thanks for the code. I have tested it several times and it works perfectly!

THANKS!


0

Related Posts

See More



Response Number 6
Name: needToCode
Date: May 15, 2009 at 17:30:15 Pacific
Reply:

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


0

Response Number 7
Name: Judago
Date: May 15, 2009 at 18:06:32 Pacific
Reply:

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


0

Response Number 8
Name: needToCode
Date: May 15, 2009 at 19:08:49 Pacific
Reply:

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.


0

Response Number 9
Name: Judago
Date: May 15, 2009 at 19:40:33 Pacific
Reply:

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


0

Response Number 10
Name: needToCode
Date: May 15, 2009 at 20:15:09 Pacific
Reply:

Within the code is there a method to encapsulate the account name variables with quotation marks?


0

Response Number 11
Name: Judago
Date: May 15, 2009 at 21:51:10 Pacific
Reply:

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


0

Response Number 12
Name: needToCode
Date: May 16, 2009 at 15:24:55 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Redirected Output To HTML

vb to html conversion ? www.computing.net/answers/programming/vb-to-html-conversion-/9890.html

Dos script to search into .txt file www.computing.net/answers/programming/dos-script-to-search-into-txt-file/16695.html

display on-screen and output to txt www.computing.net/answers/programming/display-onscreen-and-output-to-txt/17433.html