In batch script, output command in txt file
Moderator: DosItHelp
In batch script, output command in txt file
Hi everyone!
I have .bat file
and file .vbs
How can I save the output of commands?
Thank you so much! Bye
I have .bat file
and file .vbs
How can I save the output of commands?
Thank you so much! Bye
Last edited by dosbatch on 06 Dec 2016 02:08, edited 1 time in total.
Re: In batch script, output command in txt file
Why not use a scriptable telnet client?
Re: In batch script, output command in txt file
Thank you for the answer.
Because I think this is the simple way.
Can you explain how I modify the code for resolve my issue?
This script run ok but i need to receive output for one command.
If you think that scriptable telnet client is the best solution, can you explain how do you procede?
Sorry for my english
Because I think this is the simple way.
Can you explain how I modify the code for resolve my issue?
This script run ok but i need to receive output for one command.
If you think that scriptable telnet client is the best solution, can you explain how do you procede?
Sorry for my english
Re: In batch script, output command in txt file
Maybe it suffices to create a logfile (using option -f LogFile) and use a for/F loop to set the desired output:
https://technet.microsoft.com/de-de/library/cc730934(v=ws.10).aspx.
penpen
https://technet.microsoft.com/de-de/library/cc730934(v=ws.10).aspx.
penpen
Re: In batch script, output command in txt file
(for /F "tokens=*" %%A in (router.txt) do (
start telnet.exe %%A
script command.vbs
telnet -f logfile.txt %%A
))
In this case I have all output of telnet command
Tnk
start telnet.exe %%A
script command.vbs
telnet -f logfile.txt %%A
))
In this case I have all output of telnet command
Tnk
Last edited by dosbatch on 06 Dec 2016 02:12, edited 1 time in total.
Re: In batch script, output command in txt file
I had rather thought of using the -f option in your (first) telnet command, and parse the result using a for/F loop to extract the needed information:
penpen
Edit: Added missing 'c' ("cscript").
Code: Select all
(for /F "tokens=*" %%A in (router.txt) do (
start telnet.exe -f "logfile.txt" %%A
cscript command.vbs
for /F "usebackq tokens=* delims=" %%b in ("logfile.txt") do (
rem:This step depends on the structure of "logfile.txt".
)
del "logfile.txt"
))
penpen
Edit: Added missing 'c' ("cscript").
Re: In batch script, output command in txt file
This works fine:
But I would be a list of output telnet command in one file.
With this code I have only one output telnet command in log.txt
In the same log.txt I want this structure:
%%A
output telnet;
%%A
output telnet
....
for anyone items of for loop.
Tnk
Code: Select all
(for /F "tokens=*" %%A in (router.txt) do (
start telnet.exe -f log.txt %%A
cscript comandi.vbs
))
But I would be a list of output telnet command in one file.
With this code I have only one output telnet command in log.txt
In the same log.txt I want this structure:
%%A
output telnet;
%%A
output telnet
....
for anyone items of for loop.
Tnk
Re: In batch script, output command in txt file
Because of that, i've added the "for/F %%b" part:dosbatch wrote:But I would be a list of output telnet command in one file.
With this code I have only one output telnet command in log.txt
But without seeing the content of such a log-file, one can't give you detailed source code suggestions.
So if you want such, then you have to post at least one of these log files (you may disguise private data,
but list any character possible; also you may shorten text using "..." - but don't shorten important parts),
and outline the result you want to have:
You also should use code-blocks to separate text from data.
penpen
Re: In batch script, output command in txt file
With this .bat
Code: Select all
(for /F "tokens=*" %%A in (router.txt) do (
start telnet.exe -f log.txt %%A
cscript command.vbs
))
Last edited by dosbatch on 06 Dec 2016 02:13, edited 1 time in total.
Re: In batch script, output command in txt file
Basing on this log, there are some possibilities.
Lets try if the simplest solution is working:
This bases on the assumption, that the instruction "nvram commit" produces exact one output line,
which starts with a percentage character ('%'); also this is the only line starting with this character.
If the above is true, then (no "for /f" loop is needed and) this might help you (currently untested):
penpen
Edit 1-2: Somehow i've lost the 'c' in "cscript".
Lets try if the simplest solution is working:
This bases on the assumption, that the instruction "nvram commit" produces exact one output line,
which starts with a percentage character ('%'); also this is the only line starting with this character.
If the above is true, then (no "for /f" loop is needed and) this might help you (currently untested):
Code: Select all
@echo off
setlocal enableExtensions disableDelayedExpansion
set "telnetLogFile=logfile.txt"
set "logfile=log.txt"
for /F "usebackq tokens=*" %%A in ("router.txt") do (
start telnet.exe -f "%telnetLogFile%" %%A
cscript command.vbs
>> "%logfile%" (
echo(%%A
echo(
findstr /r /c:"^%%" "%telnetLogFile%"
echo(
)
del "%telnetLogFile%"
)
endlocal
goto :eof
penpen
Edit 1-2: Somehow i've lost the 'c' in "cscript".
Re: In batch script, output command in txt file
"nvram commit" produces exact one output line, which starts with a percentage character ('%'). Exactly!
But your script don't work. I don't understand...
But your script don't work. I don't understand...
Re: In batch script, output command in txt file
Hopefully the missing 'c' character was the only error in the script above.
penpen
penpen
Re: In batch script, output command in txt file
Tnk you so much!! It works fine!