How to pipe specific cmd output line to another batch?

645 views Asked by At

How to pipe specific cmd output line to another batch?

For example:

command DSQUERY USER -samid *loginname* | DSGET USER -loscr

It finds what user in AD has in his Logon script field, what is actual login script name. I want to pipe this output to another batch file which opens login script file for this specific user.

BUT output of the above command outputs three lines:

loscr
"script name"
dsget succeeded

How to suppress first and third lines and to pipe only output from second line?!

Thanks.

1

There are 1 answers

4
npocmaka On
@echo off

for /f "skip=1 tokens=*" %%a in ('command DSQUERY USER -samid *loginname*') do (
   if not defined second_line set "second_line=%%a"
)

DSGET USER -loscr %second_line%

?