1

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.

E.S
  • 536
  • 1
  • 9
  • 20
AlexSun.dr
  • 61
  • 1
  • 4

1 Answers1

1
@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%

?

npocmaka
  • 55,367
  • 18
  • 148
  • 187
  • npocmaka: Thanks. After I run batch with script you advised, cmd stops responding and doesn't provide any output. Any suggestions on this? – AlexSun.dr Nov 17 '14 at 13:18
  • remove `@echo off` to see what happens...As I have no DS on my machine I cant test the script... – npocmaka Nov 17 '14 at 13:24
  • npocmaka: without @echo it shows that it stuck/stops responding after last bracket (or before command DSGET USER -loscr %second_line% ). Thanks – AlexSun.dr Nov 18 '14 at 08:50
  • @alex change `if not defined second_line set "second_line=%%a"` with `echo %%a` to see the output of for loop.Ensure that the `command DSQUERY USER -samid *loginname*` is the thing you want to execute.... – npocmaka Nov 18 '14 at 09:07