如何使用 cmd 和日志文件在任务计划程序中调试此计划的 .bat 任务?

How to debug this scheduled .bat task in task scheduler using cmd and log file?

我尝试基本上运行将以下 .bat 文件作为计划任务,同时也在 .txt 文件中记录错误:

在'program/script'框中,我只有cmd。然后在添加参数框中我有:

/k ""T:\Some_folder\mybatchfile.bat" >>"T:\somelog.txt" 2>&1"

在我尝试添加日志功能并暂时调用 cmd explicitly as seen in several posts, but I'd really like to add this function. I'm using /k 之前,这本来工作得很好,这样我就可以在事情发生时观察 cmd window,但计划更换它与 /c 所以它在完成后关闭。

我尝试了很多 my quotation marks are but am not having a lot of luck. I'm also intentionally using >> vs > in order to append the log 的排列,而不是覆盖它。

.bat文件内容基本是:

"C:\RDirectory\R.exe" CMD BATCH          "T:\Some_folder1\Preworkforbatch.R"
copy T:\Some_folder2\some_data.csv       "C:\Users\ABC1\Another_folder"
copy T:\Some_folder3\some_more_data*.csv "C:\Users\ABC1\Another_folder"

我想知道其中是否有一部分是 T 是映射的网络文件夹?感谢您的帮助。

编辑:

这里是关于任务的更多信息:

"T:\Some_folder\mybatchfile.bat" >> "T:\somelog.txt" 2>&1

将批处理文件的输出重定向到日志文件时,您将不会在 cmd window 中看到那么多输出。你必须反复打开、关闭、打开日志文件才能看到你的进度。在批处理中使用 title 命令在 cmd window.

中显示进度信息
title This is %~F0.  The time is %time%.  The date is %date%.  SLEEP 3600 FOR :RECORDRADIO

好的,这最终对我有用,通过编辑批处理文件本身,并且只是 运行 任务计划程序中的批处理文件(不是明确的 cmd):

mybatchfile.bat:

@echo on
"C:\RDirectory\R.exe" CMD BATCH          "T:\Some_folder1\Preworkforbatch.R" >> "C:\Users\ABC1\Logfolder\mylog.txt" 2>&1
copy T:\Some_folder2\some_data.csv       "C:\Users\ABC1\Another_folder" >> "C:\Users\ABC1\Logfolder\mylog.txt" 2>&1
copy T:\Some_folder3\some_more_data*.csv "C:\Users\ABC1\Another_folder" >> "C:\Users\ABC1\Logfolder\mylog.txt" 2>&1

将日志文件写入网络导致错误。 写入本地计算机 解决了这个问题。 不使用双引号 也是关键,而只是在 file/path 周围加上引号。此设置为我提供了每一行的输出,因此对于显示 2>71 的每一行,如果有错误或完成消息,我会得到一个输出。

这是任务计划程序的样子: