question on a cool script


S

Stel

One thing I love about IT. no matter how long you do it (over 16 yrs
for me) or how good you think you are (with .cmd .bat files) you can
always learn something ... So today I'm ready to learn!

Found a cool script today using this code.

for /F "delims=" %%a in ('schtasks /query /v /fo:list ^| findstr /i
"Taskname Result"') do call :Sub %%a

While I think I'm familiar with the for /f command I've not seen the
"^" character used. This line supplies one line of output from the
schtasks utility to the :sub routine, at a time which is really cool
with findstr filtering. So can someone school me on how this ^ was
used? or send me to a URL that I can learn this. Several uses come to
mind.

Thanks in advance,

Stel

note: If you're interested this came from a script that monitors
local scheduled tasks and blats alerts
(http://forums.techarena.in/server-scripting/972774.htm)
 
Ad

Advertisements

T

Tom Lavedas

One thing I love about IT.  no matter how long you do it (over 16 yrs
for me) or how good you think you are (with .cmd .bat files) you can
always learn something ... So today I'm ready to learn!

Found a cool script today using this code.

for /F "delims=" %%a in ('schtasks /query /v /fo:list ^| findstr /i
"Taskname Result"') do call :Sub %%a

While I think I'm familiar with the for /f command I've not seen the
"^" character used.  This line supplies one line of output from the
schtasks utility to the :sub routine, at a time which is really cool
with findstr filtering.  So can someone school me on how this ^ was
used? or send me to a URL that I can learn this.  Several uses come to
mind.

Thanks in advance,

Stel

note:  If you're interested this came from a script that monitors
local scheduled tasks and blats alerts
(http://forums.techarena.in/server-scripting/972774.htm)
The carat character (^) is used to 'escape' a character that would
otherwise cause a problem when a command is initially parsed. In this
case, the vertical bar 'piping' character (|). It delays the
processing until the command contained between the single quotes gets
processed as part of the execution of the FOR. Otherwise, the initial
parsing of the statement would throw a "| was unexpected at this time"
error.

This is documented in the command shell overview of the Win GUI help
(press F1 function key from the GUI desktop check the index or and
search for "command shell"). It can also be accessed in OSs up
through XP with the following command prompt statement:

HH ntcmds.chm::/ntcmds_shelloverview.htm

I can't remember if its also documented in one of the command
prompt /? info responses.
_____________________
Tom Lavedas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Novice Script Question 7
automated script of defrag question 4
question about script for check service status 1
Script Challenge 3
Windows Scripting 1
scripting resources 2
Logon script ? 2
Download with script 3

Top