|
pusofalse
银牌会员
    
积分 1604
发帖 646
注册 2008-4-13
状态 离线
|
『楼 主』:
用实例说明管道命令,组合命令的用法(方便新手)
高手们无视吧。。。- -||
@echo off
title PORT T0 PROCESS
:1
cls&echo.&set "tmp="
set "port="
set/p "port=Input the port id: "
if not defined port goto 1
echo %port%|findstr /v /i "[a-z]">nul&&call :lp||goto 1
:lp
for /f "skip=4 tokens=3,7 delims=: " %%a in ('netstat -anop tcp') do (
echo %%a|findstr "\<%port%\>">nul&&(set tmp=A&echo.&echo PROCESS INFOMATION:&echo.&tasklist /fi "pid eq %%b" 2>nul)
)
if not defined tmp echo.&echo No %port% port running
pause>nul&goto 1
@
useage: [@command]
Hide the command which is behind it.
&
usage: [first command&second command]
No matter the first command succeed or failed, execute the second command.
&&
usage: [first command&&second command]
While first command succeed ,then second command.
||
usage: [first command||second command]
While first command failed,then second command.
|
usage: [first command|second command]
Communicate the result of first command to the parameters of the second command.
>
usage: [command>file]
Output the result of the command into a file and cover the original contents.
>>
usage: [command>>file]
Output the result of the command into a file,but will not cover the original contents. 熟用管道命令, && || 可以代替 if errorlevel 感觉简单多了啊~
|

心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^ |
|
2008-5-22 17:07 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第
2 楼』:
兄弟举的例子是不是太难懂了点啊,我都看了半天没明白过来。
[ Last edited by zw19750516 on 2008-5-22 at 05:33 PM ]
|

批处理之家新域名:www.bathome.net |
|
2008-5-22 17:31 |
|
|
pusofalse
银牌会员
    
积分 1604
发帖 646
注册 2008-4-13
状态 离线
|
『第
3 楼』:
就是输入一个端口号,输出所对应的进程。。。。 另外加了一点排错处理。。 昨晚上没事做,消遣一下的~
|

心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^ |
|
2008-5-22 17:35 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第
4 楼』:
学批处理的新手怕是难以理解啊,兄弟。
ps:好像不对啊,我的机器上196端口是开着的,但运行后却提示no run!
[ Last edited by zw19750516 on 2008-5-22 at 05:46 PM ]
|

批处理之家新域名:www.bathome.net |
|
2008-5-22 17:38 |
|
|
pusofalse
银牌会员
    
积分 1604
发帖 646
注册 2008-4-13
状态 离线
|
『第
5 楼』:
最主要的是常练习。。。 以前写过这样一个批处理,端口--进程。。。以前的代码比现在繁杂3倍之多~ 只要是还不懂for的流程~ 一心钻研下去,总会有收获的~ 我就是个例子~ 另外学了这好几个月的批处理,if errorlevel 的用法始终摸不到头脑,所以就提醒下新手可以&& ||代替If errorlevel
一下就罗嗦了这么多~ 无视吧
|

心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^ |
|
2008-5-22 17:46 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第
6 楼』:
修改:
@echo off
title PORT T0 PROCESS
:1
cls&echo.&set "tmp="
set "port="
set/p "port=Input the port id: "
if not defined port goto 1
echo %port%|findstr /v /i "[a-z]">nul&&call :lp||goto 1
:lp
for /f "skip=4 tokens=3,7 delims=: " %%a in ('netstat -anop tcp') do (
echo %%a|findstr /c:"%port%">nul&&(set tmp=A&echo.&echo PROCESS INFOMATION:&echo.&tasklist /fi "pid eq %%b" 2>nul)
)
if not defined tmp echo.&echo No %port% port running
pause>nul&goto 1
|

批处理之家新域名:www.bathome.net |
|
2008-5-22 17:51 |
|
|
pusofalse
银牌会员
    
积分 1604
发帖 646
注册 2008-4-13
状态 离线
|
『第
7 楼』:
Quote: | Originally posted by zw19750516 at 2008-5-22 05:38 PM:
学批处理的新手怕是难以理解啊,兄弟。
ps:好像不对啊,我的机器上196端口是开着的,但运行后却提示no run!
[ Last edited by zw19750516 on 2008-5-22 at 05:46 PM ] |
|
啊! 抱歉抱歉,忘记说了~ 这段代码只能检测TCP端口~ - -||||
|

心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^ |
|
2008-5-22 17:54 |
|
|
pusofalse
银牌会员
    
积分 1604
发帖 646
注册 2008-4-13
状态 离线
|
『第
8 楼』:
findstr /c 不是匹配多个字符串吗?~
findstr "\<%port%\>" 不是精确匹配吗~
PS。前辈的代码貌似也有点问题,我没开35端口,只开着135 但输入35 却跟输入135 输出同样的结果~ SVCHOST.EXE
[ Last edited by pusofalse on 2008-5-22 at 06:05 PM ]
|

心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^ |
|
2008-5-22 17:57 |
|