I want to schedule a batch file to execute a command and redirect that output a text file

0

I want to schedule a batch file to execute a command and redirect that output a text file.

This is my current solution:

Del \\10.112.232.10\Netbackup_Softwares\Personal\Bharath\VM_Query\switch.txt
D:\VMware_Query\VM_Query.bat >> \\10.112.232.10\Netbackup_Softwares\Personal\Bharath\VM_Query\switch.txt

Windows Server 2012

When I tried with task scheduler its executing the command but not redirecting output to text file.

Command works fine when I execute from cmd prompt.

user3016638

Posted 2016-05-12T03:10:38.123

Reputation: 1

can someone help me with this. – user3016638 – 2016-05-12T07:01:43.510

Can you post the logic which is in your batch file VM_Query.bat? I would put the << %logfilename% in that file and just have the schedule pass the UNC full pass as an argument and then delete if exist and all the rest. Post the batch logic from your file to an edit on your answer and I will show you how to EASILY get this to work and provide an answer with a precise example I test and confirm to work just as you describe. – Pimp Juice IT – 2016-05-14T14:12:34.110

Answers

0

Please check the following options in the task scheduler UI,

  • When running the task, use the following user account:
  • Run whether user is logged on or not

And just for troubleshooting, try to schedule the task for once storing the output to a local drive (instead of an UNC path)

Hope this helps.

hkdtam

Posted 2016-05-12T03:10:38.123

Reputation: 309

I have the correct checks enabled for the task scheduler UI. I need to redirect this to UNC path instead local disk. Task scheduler runs the command its not redirecting the O/P. – user3016638 – 2016-05-12T03:34:43.523

@user3016638 - Just to clarify further, if you changed the command (just for troubleshooting) did the task run underschedule was able to write to a local file? – hkdtam – 2016-05-12T03:48:15.827

I didn't try on local disk but that wont help me – user3016638 – 2016-05-12T04:33:12.147

@user3016638 - Oh I see. That was only a measure trying to isolate the problem scope. – hkdtam – 2016-05-12T06:02:42.863