I created a batch file as below:
set VAR1=VALUE1
start another_batch_file
sleep 10
ps -l |grep abc > foo.txt
another_batch_file would start several processes, I want to use ps to list some specific ones. This script works well when I run it from a cmd window, although if I create a task in Task Scheduler to call this script automatically the foo.txt will be empty.
I also tried to output the ps -l
result to a file, it's also empty
ps & grep both from MKS toolkit.
Edit:
Per the comments, I have tried with the script similar to the following:
set VAR1=VALUE1
start another_batch_file
sleep 10
ps > foo.txt
tasklist > bar.txt
Now foo.txt is still empty, while bar.txt has normal output which contains all the processes' information.
Any one has a clue?
Edit 2:
I have the box "Run with highest privileges" checked and the the ps
command works well now.
I have been using the same user account when run the script in a cmd window or by a scheduled task, although the ps
exeutable file located in a mapped drive, I think this caused the script needs higher privileges to run
If it works at the prompt: task scheduler runs in the system account by default and has no access to network resources, and if your other batch file is trying to access them then it will not load.