我有一个小脚本,crontab每天使用以下命令调用它:
/homedir/MyScript &> some_log.log
Run Code Online (Sandbox Code Playgroud)
此方法的问题是some_log.log仅在MyScript完成后创建.我希望在程序运行时将程序的输出刷新到文件中,这样我就能做到这样的事情
tail -f some_log.log
Run Code Online (Sandbox Code Playgroud)
并跟踪进度等
这是一个简单的批处理文件,它演示了如果延迟扩展在正在通过管道传输的块中,它将如何失败.(失败是在脚本的末尾)任何人都可以解释为什么这是?
我有一个解决方法,但它需要创建一个临时文件.我最初在查找文件时遇到了这个问题,并在Windows批处理文件中按大小排序
@echo off
setlocal enableDelayedExpansion
set test1=x
set test2=y
set test3=z
echo(
echo NORMAL EXPANSION TEST
echo Unsorted works
(
echo %test3%
echo %test1%
echo %test2%
)
echo(
echo Sorted works
(
echo %test3%
echo %test1%
echo %test2%
) | sort
echo(
echo ---------
echo(
echo DELAYED EXPANSION TEST
echo Unsorted works
(
echo !test3!
echo !test1!
echo !test2!
)
echo(
echo Sorted fails
(
echo !test3!
echo !test1!
echo !test2!
) | sort
echo(
echo …Run Code Online (Sandbox Code Playgroud)