0

I'm trying to basically run the following .bat file as a scheduled task, while also logging errors in a .txt file:

enter image description here

In the 'program/script' box, I just have cmd. Then in the add arguments box I have:

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

This had been working just fine originally before I tried to add the log function and calling cmd explicitly as seen in several posts, but I'd really like to add this function. I'm using /k for now so that I can watch the cmd window as things happen, but plan to replace it with /c so it closes when its done.

I tried many permutations of where my quotation marks are but am not having a lot of luck. I'm also intentionally using >> vs > in order to append the log, not overwrite it.

The contents of the .bat file are basically:

"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"

I'm wondering if part of it is that T is a network folder that is mapped? Thanks for your help.

edit:

Here is more info on the task:

enter image description here

SqueakyBeak
  • 366
  • 4
  • 15
  • It may be possible that the user under whom the task is being run, does not have access to the network location. Whether that's because the network hasn't been established yet, or a permission issue, is unknown at this time, _(because you haven't provided all of the scheduled task information)_. – Compo Jan 08 '20 at 00:43
  • The user has access to the network location – SqueakyBeak Jan 08 '20 at 01:29
  • ...and, what about the other information? – Compo Jan 08 '20 at 02:14
  • Have added an additional screenshot, let me know specifically if something else should be added – SqueakyBeak Jan 08 '20 at 14:38
  • A cmd window will open and you will see no progress. Open your logfile to see the progress. Close and open the logfile to see more progress. – somebadhat Jan 08 '20 at 14:41
  • If I wanted to see the progress do I just add 'echo' after /c? – SqueakyBeak Jan 08 '20 at 16:02
  • The log file is not updating unf – SqueakyBeak Jan 08 '20 at 16:14
  • To notify a previous commenter mention their user name: `@som or @somebadhat` will both work. See https://stackoverflow.com/help/privileges/comment – somebadhat Jan 09 '20 at 13:23

2 Answers2

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

When redirecting the output of a batch file to a log file you will not see as much output in the cmd window. You have to repeatedly open, close, open the log file to see your progress. Use the title command in your batch to display progress info in the cmd window.

title This is %~F0.  The time is %time%.  The date is %date%.  SLEEP 3600 FOR :RECORDRADIO

screenshot of task

somebadhat
  • 744
  • 1
  • 5
  • 17
0

Ok this ended up working for me, by editing the batch file itself, and just running the batch file (not cmd explicitly) in the task scheduler:

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

Writing the log file to the network was causing errors. Writing to the local computer solved this issue. Not using double quotes also was key, instead just quotes around the file/path. This setup gives me an output for each line, so for every line 2>71 shows up, I get an output if there's an error or a completion message.

This is what the task scheduler looks like: enter image description here

SqueakyBeak
  • 366
  • 4
  • 15