代码之家  ›  专栏  ›  技术社区  ›  user8785018

“进程试图写入不存在的管道。”bat文件

  •  3
  • user8785018  · 技术社区  · 7 年前

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

    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:\Users\test>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
    

    谢谢你的帮助//西蒙

    3 回复  |  直到 7 年前
        1
  •  3
  •   Compo    7 年前

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

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

    添加computername(当我解释 comment 正确):

    @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-address , MAC-address , Computer-name . 调整 echo 符合您的需求。
    您可能需要调整标记( tokens=5 )(内部 for )对于您的语言。
    您可能需要添加 delims=. 到内部 对于 仅获取计算机名称。

    根据您的评论:

    @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
    
        3
  •  0
  •   bambams    6 年前

    我在无意中将批处理脚本传输到MSYS时多次收到此错误 grep 当我真的打算在事后提交一个文件时:

    > call foo.cmd | grep pattern path\to\file
    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 需要执行的操作会导致此错误(my 富。cmd命令 是相当长和复杂的),但我想我还是要在这里加上这个。希望它能帮助一些人(甚至是我自己)。我想说的是:

    > call foo.cmd && grep pattern path\to\file