Redirect the "Puts" Command Output to a Log File

Redirect the puts command output to a log file

I should recommend to use ruby logger, it is better than puts, you can have multiple log levels that you can turn on/off: debug, warn, info,error, etc.

 logger = Logger.new(STDOUT)
logger = Logger.new("/var/log/my-daemon.log")

I use runit package to manage ruby services, it has svlogd than will redirect daemon output to log file, here is run script for logger process:

#!/bin/sh
set -e

LOG=/var/log/my-daemon

test -d "$LOG" || mkdir -p -m2750 "$LOG" && chown nobody:adm "$LOG"
exec chpst -unobody svlogd -tt "$LOG"

redirect command output to a file

This is ICC2, which means you can use the redirect command that Synopsys includes with their tools.

fc_shell> man redirect
2. Synopsys Commands Command Reference
redirect

NAME
redirect
Redirects the output of a command to a file.

SYNTAX
string redirect
[-append] [-tee] [-file | -variable | -channel] [-compress]
[-bg]
[-max_cores number_of_cores]
target
{command_string}

Data Types
number_of_cores integer
target string
command_string string

Instead of using puts $fp, you can redirect the stdout to a filename.

set my_nets [get_nets *user given nets*]

redirect -file "connectivity.txt" {
foreach_in_collection net $my_nets {
set my_net [get_object_name $net]
set cmd "check_lvs -nets $my_net -checks open -open_reporting bounding_box -max_errors 0"
puts "checking for: $my_net"
eval $cmd
}
}

How to send entire output in command prompt to log file to display time change and errors

Achieving this, is quite easy. There are two ways: do it inside a batch file:

setlocal EnableDelayedExpansion
(
echo Logged time = !time! !date!

@echo off
echo !time

schtasks /Change /disable /TN \Microsoft\Windows\Shell\FamilySafetyMonitor
timeout 5 > NUL
echo !time!

schtasks /Change /disable /TN \Microsoft\Windows\Shell\FamilySafetyMonitorToastTask
timeout 5 > NUL
echo !time!

schtasks /Change /disable /TN \Microsoft\Windows\Shell\FamilySafetyRefreshTask
timeout 5 > NUL
echo !time!

schtasks /Change /disable /TN "\Microsoft\Windows\Power Efficiency Diagnostics\AnalyzeSystem"
timeout 5 > NUL
echo !time!

schtasks /Change /disable /TN \Microsoft\Windows\Maps\MapsToastTask
timeout 5 > NUL
echo !time!

schtasks /Change /disable /TN \Microsoft\Windows\Maps\MapsUpdateTask
timeout 5 > NUL
echo !time!

schtasks /Change /disable /TN "\Microsoft\Windows\Mobile Broadband Accounts\MNO Metadata Parser"
timeout 5 > NUL
echo !time!

schtasks /Change /disable /TN "\Microsoft\Windows\Windows Error
Reporting\QueueReporting"
timeout 5 > NUL
echo !time!

schtasks /Change /disable/TN \Microsoft\Windows\Defrag\ScheduledDefrag
timeout 5 > NUL
echo !time!

schtasks /Change /disable /TN "\Microsoft\Windows\Windows MediaSharing\UpdateLibrary"
timeout 5 > NUL
echo !time!

schtasks /Change /disable /TN \Microsoft\Windows\Maintenance\WinSAT
timeout 5 > NUL
echo !time!
)>>TaskSetBatchScripts.log 2>&1

Not sure what you need here: append (>>) or redirect (>) [erase previous content].

The second way is to run the file from cmd like this:

(filename.bat)>>TaskSetBatchScripts.log 2>&1

Not sure again what you need.

(A 3rd way would be to append each command's output to a file adding 2>&1).

How to redirect net command output to file in windows batch file?

net stop SPTimerV4 >> mylog.log 2>&1 is what you're looking for.

This works by redirecting all normal output to the log file (the >>) and redirecting error output a copy of the normal output at that moment, which is appending to a file.

Because it redirects to a copy, you can't actually switch them around (eg. 2>&1 1>> mylog.log won't work)

For more information regarding redirection, please look here



Related Topics



Leave a reply



Submit