1.

Solve : Tasklist not outputting to file when run from batch?

Answer»

Tasklist isn't outputting to file when run from a batch file. It will CREATE the file, just won't write anything to it.

It works perfectly otherwise when I run it in cmd.exe

Code: [SELECT]tasklist /FO CSV >"output.txt"
Not sure why.tasklist /fo csv>output.txt

This worked for me without the " " and bound tight csv>output.txtQuote from: DaveLembke on June 06, 2013, 07:38:27 PM

tasklist /fo csv>output.txt

This worked for me without the " " and bound tight csv>output.txt
Hm, that still gave me an EMPTY file when ran from a batch file.Quote from: bbman12 on June 06, 2013, 06:51:04 PM
Tasklist isn't outputting to file when run from a batch file. It will create the file, just won't write anything to it.

Code: [Select]tasklist /FO CSV >"output.txt"

It works fine here - copy and pasted.

You batch file isn't called tasklist is it?Quote from: foxidrive on June 06, 2013, 07:44:34 PM
You batch file isn't called tasklist is it?
Wow, I WOULD have never imagined that would affect anything. That fixed it, thanks.GOOD CATCH Foxidrive!!! Quote from: bbman12 on June 06, 2013, 07:54:26 PM
Wow, I would have never imagined that would affect anything. That fixed it, thanks.

Of course it will affect plenty! When a batch script finds a command which is not an internal command like DIR etc, it first looks in the current folder for a executable program or script with that name, if that fails it then searches through the folders listed in the PATH variable. If you name the batch the same as a command, if the batch finds itself first, it will call itself. You couild avoid this by using the extension as well as the name - tasklist.exe - in a batch script but it is very bad idea to name batch scripts the same as Windows commands.


I think that is the 3rd time I have seen SOMEONE make that mistake this week.


Discussion

No Comment Found