0

I am trying to use the NSlookup command in a batch file. If I type the command in CMD prompt it works properly: resolves and echos the IP. If I use the same command in a batch script I get the error "The process tried to write to a nonexistent pipe" and a whole lot of ^C's over and over. What is wrong with my command?

In CMD I enter:

for /f "tokens=2 delims=: " %i in ('nslookup %domain%^|find "Address"') do echo 
address=%i

and for batch command I am using:

for /f "tokens=2 delims=: " %%i in ('nslookup %domain%^|find "Address"') do echo 
address=%%i
8
  • 1
    White space counts. Put the entire thing on one line and it works. Jan 12, 2015 at 23:42
  • I don't think there was a space in it to begin with, I think it was just a notepad word wrap. I made sure that it was all on one line and I still get the same results. Thank you for your quick response
    – Konan
    Jan 13, 2015 at 12:51
  • Are you sure that domain is defined? When I don't define it the batch file simply hangs and does nothing, but otherwise it works just fine. Jan 13, 2015 at 15:06
  • I am acutally not using a variable in my batch file, just to make sure that isn't the problem. I only changed it so as to protect information. This is why I am perplexed, it seems so simple I can't figure out why it is fighting me. I thought it may be security policies at my company but they said no.
    – Konan
    Jan 13, 2015 at 15:20
  • Run it again and copy the resulting output to your question. Jan 13, 2015 at 17:07

2 Answers 2

0

Apparently I have been using the correct syntax, I randomly clicked on the same script file and it worked. The only thing I have changed recently is specifying the absolute path for nslookup but that didn't even work at the time when I did it. Thanks for your help everyone!

-1

This means that the pipe has been somehow closed. This could be a problem with using find.

Try using findstr instead of find.

1
  • I tried changing to findstr and I also get identical results. Thank you for the reply though.
    – Konan
    Jan 13, 2015 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.