Writing pings to files batch - windows

Im looking for the best way to write two instances of cmd ping commands to 2 seperate text files using a batch file.
Here is what I have but its not writing to the file im wondering why.
start cmd /k ping 8.8.8.8 -t >> c:\troubleshoot_connection_google.txt
start cmd /k ping 192.x.x.x -t >> c:\troubleshoot_connection_gateway.txt
Thanks for the help.

The problem with your commands, appart from the point that the root folder of the drive is usually not writteable, is when the redirection to the output file is done.
As you have it written, what is being redirected to the file is the output of the start command, but if you need to redirect the output of the ping command, the redirection must be part of the started command
start "" "cmd /c ping 8.8.8.8 -t >> c:\troubleshoot_connection_google.txt"

Related

Piping output of process to file asynchronously in windows

I am trying to run a program using "start" and I want to have the output piped to a txt file, for example, I want to have the output of a simple http python server to be logged to a text file:
START cmd /c python -m SimpleHTTPServer 8000^>engineLog.txt
The above will print it to the log file but the problem with that is, it only prints it when the process finishes. Are there any way that I can store it to the log as it is running? Also is it possible to have it log in the txt file as well as having it print out in the console?
Give it a try:
START /b "Your title" "cmd /c python -m SimpleHTTPServer 8000 > engineLog.log | type engineLog.log"
Alternatively, you can get tee port for Windows.

How to open a .txt file after using netstat command with Batch

I am trying to open a simple log.txt file (in this example comandos.txt) after running a netstat command like so:
# echo off
echo. >> C:\comandos.txt
netstat -b -o 1 >> C:\comandos.txt
start C:\comandos.txt
After netstat Prompt Windows won't close and comandos.txt won't open.
Any clues on how to solve this?
# echo off
echo. >> C:\comandos.txt
netstat -b -o >> C:\comandos.txt
start C:\comandos.txt
The above snippet works fine. Note that you were specifying the interval in netstat command which redisplays the statistics again and again. Also, because you have echo turned off and display redirected to the file, the empty prompt window showing up for a long time would send wrong signals. Show some message like Collecting information... or similar.
Also, given that the command needs to resolve addresses and depends on the number of processes with network connection, it may take some time for netstat to complete which would be system dependent.

Change PING script to TELNET script?

I need to turn this ping script into a telnet script which I'd like to configure the script to telnet to the address (on my separate target list *.txt file) & either:
connect/disconnect - write success results to file
or
fail - write fail results to file,
& go to next record, then end...
HELP? :)
#echo off
cls
echo Ping test in progress...
for /F %%i in (iplist.txt) do ping -n 3 -a %%i >> result.txt
echo .
echo .
echo Result is ready.
You cannot simply replace ping with telnet. For one thing, the telnet shipped with Windows isn't scriptable in the first place, so you'd have to jump through some hoops to make it work in a script. You'd be better off using a telnet that's actually scriptable, like plink from the PuTTY suite. Also telnet clients can talk to arbitrary services, so you need to specify where you want to connect to (a telnet server uses a different protocol than, say, a web server or a mail server).

Redirect output processed via vbscript (cscript) to file

Issue with command output:
I am attempting to have a continuous ping report back to a text file.
Started with:
ping 127.0.0.1 -t >> C:Textping.txt
Works great
I also want to have timestamps listed before each ping
So Wrote:
Dim str
Do While Not WScript.StdIn.AtEndOfStream
str = WScript.StdIn.ReadLine
WScript.StdErr.WriteLine now & " - " & str
Loop
Saved it as timestampLog.vbs on my desktop and dropped a copy into my system 32 folder.
Put all of this into a batch file:
ping 127.0.0.1 -t | cscript //nologo timestamplog.vbs >> C:Pingtest1.txt
It works perfectly except that the output is printing to command prompt and Pingtest1.txt while created by the batch file is empty.
Can someone please assist me with getting the output to Pingtest1.txt?
You are running it with cscript, and writing output to STDERR (using WScript.StdErr.WriteLine). So you could use:
ping 127.0.0.1 -t | cscript //nologo timestamplog.vbs 2> C:/Pingtest1.txt
^^
> denotes STDOUT, 2> denotes STDERR.

batch: how to redirect the output of a command to a file

ping google.com >> ping.txt
that dosent work if i put it in a batch file and run the file
this is the output of ping.txt:
C:\Users\User\Desktop>ping google.com 1>>ping.txt
C:\Users\User\Desktop>ping google.com 1>>ping.txt
.
.
.
You're doing something strange with pipes.
This (from command line) will append the ping result to ping.txt file.
ping www.google.com >> ping.txt
Now create a batch file (testping.bat, for example) and put the same line inside it.
If you run the batch file with following command you'll get the same result.
testping
If you redirect the output of the batch itself then what you'll get is the echo of the batch file commands! This is why this will not work as expected:
testping >> ping.txt

Resources