Board logo

标题: [游戏娱乐] 批处理本机多进程通信和局域网通信,无第三方,无临时文件 [打印本页]

作者: Blitz    时间: 2023-8-24 13:51     标题: 批处理本机多进程通信和局域网通信,无第三方,无临时文件

本帖最后由 老刘1号 于 2023-9-16 12:00 编辑

就是靠waitfor来传递
发送.bat
  1. @echo off
  2. for /f %%a in ('echo prompt $H^|cmd') do set "bs=%%a"
  3. title 发送
  4. :1
  5. set "key="
  6. for /f "delims=" %%a in ('xcopy /w . 2^>nul') do if not defined key set "key=%%a"
  7. set key=%key:~-1%
  8. if "%key%" == "" (
  9.     echo=
  10.     set key=enter
  11. ) else if "%key%" == "%bs%" (
  12.     <nul set/p=%bs% %bs%
  13.     set key=backspace
  14. ) else if "%key%" == " " (
  15.     <nul set/p=_%bs%
  16.     set key=space
  17. ) else <nul set/p=%key%
  18. >nul waitfor /si %key%
  19. goto 1
复制代码
接收.bat
  1. @echo off
  2. for /f %%a in ('echo prompt $H^|cmd') do set "bs=%%a"
  3. title 接收
  4. if not "%1" == "" goto a
  5. for %%a in (0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z enter backspace space) do start /b "" "%~f0" %%a
  6. pause>nul
  7. exit
  8. :a
  9. >nul waitfor %1
  10. if "%1" == "enter" (
  11.     echo=
  12. ) else if "%1" == "backspace" (
  13.     <nul set/p=%bs% %bs%
  14. ) else if "%1" == "space" (
  15.     <nul set/p=_%bs%
  16. ) else <nul set/p=%1
  17. goto a
复制代码
不过只支持英文、退格、空格、回车,上面的代码还没写标点符号,可以自己加

写到一个窗口里,用了终端控制符,临时赶出来的,比较潦草杂乱:
  1. @echo off
  2. title demo
  3. mode 60,40
  4. rem 读的初始位置
  5. set r_h=3
  6. set r_l=15
  7. rem 写的初始位置
  8. set response_w=22;15
  9. for /f %%a in ('echo prompt $H^|cmd') do set "bs=%%a"
  10. for /f %%a in ('echo=prompt $E^|cmd') do set "esc=%%a"
  11. if not "%1" == "" goto a
  12. echo=加载中....
  13. for %%a in (0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z enter backspace space) do start /b "" "%~f0" %%a&&ping 127.1 /n 1 >nul
  14. cls
  15. ping 127.1 /n 2 >nul
  16. set/pa=%esc%[20;1H<nul
  17. echo=============================================================
  18. set/pa=%esc%[%r_h%;%r_l%H<nul
  19. :1
  20. set "key="
  21. for /f "delims=" %%a in ('xcopy /w . 2^>nul') do if not defined key set "key=%%a"
  22. set key=%key:~-1%
  23. if "%key%" == "" set key=enter
  24. if "%key%" == "%bs%" set key=backspace
  25. if "%key%" == " " set key=space
  26. call :draw %key%
  27. >nul waitfor /si %key% /s 192.168.1.7
  28. goto 1
  29. :a
  30. >nul waitfor %1
  31. if "%1" == "enter" (
  32.     echo=
  33.     <nul set/p=_%bs%              
  34. ) else if "%1" == "backspace" (
  35.     <nul set/p=%bs% %bs%
  36. ) else if "%1" == "space" (
  37.     <nul set/p=_%bs%
  38. ) else (
  39.     <nul set/p=%1
  40. )
  41. goto a
  42. :draw
  43. if "%1" == "enter" (
  44.     set/pa=%esc%[%response_w%H<nul
  45.     echo=
  46.     <nul set/p=_%bs%              
  47.     call :get_cursor_pos pos response_w
  48.     set/ar_h+=1
  49.     set r_l=15
  50.     set/pa=%esc%[%r_h%;%r_l%H<nul
  51. ) else if "%1" == "backspace" (
  52.     set/pa=%esc%[%response_w%H<nul
  53.     <nul set/p=%bs% %bs%
  54.     call :get_cursor_pos pos response_w
  55.     set/ar_l-=1
  56.     set/pa=%esc%[%r_h%;%r_l%H<nul
  57. ) else if "%1" == "space" (
  58.     set/pa=%esc%[%response_w%H<nul
  59.     <nul set/p=_%bs%
  60.     call :get_cursor_pos pos response_w
  61.     set/ar_l+=1
  62.     set/pa=%esc%[%r_h%;%r_l%H<nul
  63. ) else (
  64.     set/pa=%esc%[%response_w%H<nul
  65.     <nul set/p=%1
  66.     call :get_cursor_pos pos response_w
  67.     set/ar_l+=1
  68.     set/pa=%esc%[%r_h%;%r_l%H<nul
  69. )
  70. exit /b
  71. :get_cursor_pos
  72. set "response="
  73. set pos=2
  74. :_get_loop
  75. <nul set /p "=%esc%[6n"
  76. for /l %%# in (1 1 %pos%) do pause<con>nul
  77. set "char=;"
  78. for /f "tokens=1 skip=1 delims=*" %%c in ('"replace /w ? . < con"') do set "char=%%c"
  79. set "response=%response%%char%"
  80. set /a pos+=1
  81. if "%char%" neq "R" goto :_get_loop
  82. set %2=%response:~0,-1%
  83. exit /b
复制代码
缺点就是双方同时发送内容的话会有bug,还有写的时候是在一台电脑写的,所以两台电脑的读部分也会随着写部分位移
删不到上一行、大小写没做处理
作者: JUNGLEOBA    时间: 2024-3-12 22:08

厉害,厉害




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2