Question

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

Was it helpful?

Solution

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.

OTHER TIPS

A batch file isn't never in the process list. Batch files are executed by cmd.exe, so cmd.exe is in the list.

But you should be able to access it with ps, if you add a switch for displaying the parameters, too.

It's also possible with tasklist.

tasklist /FI "IMAGENAME eq cmd.exe" /V | grep another_batch_file

C:\Windows\system32\cmd.exe - another_batch_file.bat cmd.exe
1320 Console 1 3.132 K Unknown

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top