"The process tried to write to a nonexistent pipe."蝙蝠文件



我可以在命令行上运行这个循环:

for /f "tokens=2" %i in ('arp -a ^| Find/i "dynamic"') do echo %i

但是如果我运行相同的 bat 文件,我会得到:

^C^C^C^Cthe process tried to write to a nonexistent pipe^C^C^C^C^C^C^C^C^

C:\1\测试.bat:

for /f "tokens=2" %%i in ('arp -a ^ |Find/i "dynamic"') do echo %%i

由您的 arp -a 命令返回:

C:Userstest>arp -a
Interface: xxx.xx.xxx.40 --- 0xbe
Internet Address      Physical Address
 xxx.xx.xxx.18           xx-xx-xx-xx-xx-xx     dynamic
 xxx.xx.xxx.26           xx-xx-xx-xx-xx-xx     dynamic
 xxx.xx.xxx.34           xx-xx-xx-xx-xx-xx     dynamic
 xxx.xx.xxx.114          xx-xx-xx-xx-xx-xx     dynamic

感谢您的任何帮助//西蒙

您在管道之前引入了一个额外的空格字符, | .因此,插入符号 ^具有转义空格的效果,并且管道没有按应有的方式转义。

@For /F "Tokens=2" %%i In ('arp -a ^| Find /I "dynamic"') Do @(Echo %%i)>>"%~dp0output.txt"

添加计算机名(当我正确解释您的评论时(:

@echo off
for /f "tokens=1,2" %%a in ('arp -a^|find "dynam"') do (
  for /f "tokens=5" %%c in ('ping -a -n 1 %%a^|find "["') do (
    >>"%~dp0output.txt" echo %%a    %%b %%c
  )
)

显示IP-addressMAC-addressComputer-name。根据您的需求调整echo生产线。
您可能需要根据自己的语言调整令牌(tokens=5((内部for(。
您可能希望将delims=.添加到内部for以仅获取计算机名称。

根据您的评论:

@echo off
setlocal EnableDelayedExpansion
set number=0
for /f "tokens=1,2" %%a in ('arp -a^|find "dynam"') do (
  set /a number +=1
  for /f "tokens=5" %%c in ('ping -a -n 1 %%a^|find "["') do (
    >>"%~dp0output.txt" echo %%b Computer!number!
  )
)

输出:

00-24-fe-xx-xx-xx  Computer1
f4-f5-e8-xx-xx-xx  Computer2
48-d6-d5-xx-xx-xx  Computer3
d4-85-64-xx-xx-xx  Computer4
80-86-f2-xx-xx-xx  Computer5
24-77-03-xx-xx-xx  Computer6
fc-db-b3-xx-xx-xx  Computer7
80-1f-02-xx-xx-xx  Computer8
当我

真的打算在之后 grep 文件时,我不小心将批处理脚本管道到 MSYS grep时反复收到此错误:

> call foo.cmd | grep pattern pathtofile
The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.
...

我无法确切地确定foo.cmd需要做什么才能导致此错误(我的foo.cmd非常长且复杂(,但我想无论如何我都会在这里添加这个。希望它能帮助某人(甚至几个月后对我自己(。我想说的是:

> call foo.cmd && grep pattern pathtofile

最新更新