标题: [其他] cmd 命令行都有哪些黑科技? [打印本页]
作者: plp626 时间: 2016-10-4 18:44 标题: cmd 命令行都有哪些黑科技?
本帖最后由 plp626 于 2016-10-4 18:54 编辑
今天在论坛捡到俩宝贝,感觉非常实用,分享如下:
dos游戏底层新方法:
不需要choice.exe和回车就能获得按键输入的方法/黑科技
any2bat新方法:
用 certutil 实现 Hex2Bin 和 Base64 加解密
分享下我之前收集的黑科技(年代久了,你们也许觉得太平常,但第一次见到时,心里那感觉,。。。你懂的,废话少说,分享如下:
定时关机,出处不详 //当年用电脑只会点鼠标打字的我,第一次被震慑到了:- :: 1小时后关机
- shutdown -f -s -t 3600
复制代码
chm文件反编译(把chm解包成html):// 曾经发现有个exe软件就这个功能竟然还收费,真是欺负小朋友
批处理版chm文件反编译器V1.3
- ::核心代码
- hh -decompile . test.chm
复制代码
作者: plp626 时间: 2016-10-4 18:52
- :: windows下复制/备份某个目录下的特定文件 // 工作中特别方便实用
- dir/a-d/b/s *.conf *.lst > 1.txt
- rar a -m0 bak.rar @1.list
复制代码
作者: codegay 时间: 2016-10-4 20:37
是编码不是加密
作者: 523066680 时间: 2016-10-4 22:55
回复 3# codegay
这个看使用情况吧,面对一般用户,还是面对程序员
作者: CrLf 时间: 2016-10-5 01:18
最喜欢的莫过于:复制代码
作者: codegay 时间: 2016-10-5 04:23
bcn显然是个黑科技。
作者: CrLf 时间: 2016-10-5 14:19
回复 5# plp626
笔误,实际上要说的是以下两个用法复制代码
作者: Bella 时间: 2016-10-5 16:22
本帖最后由 Bella 于 2016-10-20 02:31 编辑
回复 7# CrLf
类似的问题, windows新建点号开头的文件
命令行下可以复制代码
桌面下必须前后都带点号复制代码
作者: CrLf 时间: 2016-10-5 23:38
本帖最后由 CrLf 于 2016-10-5 23:40 编辑
回复 6# codegay
那末就贴上来吧:Batch-CN——在线第三方管理,已收集1600+第三方[2016.04.24更新]
实际上已经 1800+ 了,网页版:http://www.bathome.net/s/tool/index.html
作者: CrLf 时间: 2016-10-6 12:42
对了,不能不提 用 nslookup 获取本机外网 IP
作者: codegay 时间: 2016-10-6 13:57
回复 10# CrLf
稳定性有点差。- nslookup myip.opendns.com resolver1.opendns.com
- 服务器: resolver1.opendns.com
- Address: 208.67.222.222
-
- DNS request timed out.
- timeout was 2 seconds.
- *** 请求 resolver1.opendns.com 超时
复制代码
作者: plp626 时间: 2016-10-6 21:16
回复 10# CrLf
这个有些环境不准
作者: freesoft00 时间: 2016-10-7 12:46
对了,不能不提
CrLf 发表于 2016-10-6 12:42
加路由的环境不准确,获得的是私有地址。
另外有什么好的方法判断本机可以上网?
1、通过检测dns,这个不准确,在有路由器的环境,有时候dns是路由器地址。
2、ping一个网址,这个也不稳定,1你的环境可以ping同,其他人的网络运营商环境下也许ping不同,2有些网址禁止ping,或者有些网址被屏蔽无法ping到。
作者: /zhqsystem/zhq 时间: 2016-10-7 16:21
本帖最后由 /zhqsystem/zhq 于 2016-10-7 16:54 编辑
回复 13# freesoft00
判断上网可以用路由追踪,追踪任意一个IP当IP首字段不等于局域网地址和保留地址时就可以判定可以联网了[也有弊端,dns不通QQ能上网,网页打不开会判断无法联网]
简易代码
- tracert.exe -d -w 1 "microsoft.com" >nul 2>nul&&(echo,网络连接正常)||(echo,网络连接异常,无法解析)
复制代码
作者: freesoft00 时间: 2016-10-7 17:07
回复 14# /zhqsystem/zhq
谢谢!这个应该也有我说的那个第二点的情况把,我原来是通过ping微软的网址判断的,但是后来把代码给其他人用他反映代码显示无法连接网络致使后续代码无法运行,我想是它那里ping不同,所以固定的网址有这个问题。
作者: Bella 时间: 2016-10-8 01:08
本帖最后由 Bella 于 2016-10-19 19:37 编辑
回复 14# /zhqsystem/zhq
mtr
winMTR
作者: Bella 时间: 2016-10-8 01:27
回复 15# freesoft00
ping百度就行了, 我觉得百度就是用来ping的
作者: aa77dd@163.com 时间: 2016-10-8 01:32
回复 17# Bella
举十指十趾赞成, 那就是那货最大的用处
作者: happy886rr 时间: 2016-10-10 20:56
本帖最后由 happy886rr 于 2016-10-10 20:59 编辑
生成utf8复制代码
作者: 523066680 时间: 2016-10-10 23:35 标题: 突然想起锟斤拷
本帖最后由 523066680 于 2016-10-10 23:37 编辑
- [ef bb] [bf e9] [b4 a8]
- GBK 锘 块 川
- [ef bb bf] [e9 b4 a8 ]
- UTF8 BOM 鴨
复制代码
作者: bailong360 时间: 2016-10-16 15:33
bat吧的Byaidu曾经发现过一个管道的特技
第一眼看到被惊艳了,感觉非常有趣,很有潜力,大概是这个样子
demo.bat 主程序复制代码
makelist.bat 生成数列- @echo off
- for /l %%i in (1 1 20) do (
- echo %%i
- ping -n 1 localhost >nul
- )
复制代码
output.bat 输出- @echo off
- :loop
- set n=
- set /p n=
- if not "%n%"=="" (
- set /a "n=1<<n"
- call echo %%n%%
- goto loop
- ) else echo end!
复制代码
双击Demo.bat看效果
作者: pcl_test 时间: 2016-10-16 16:47
本帖最后由 pcl_test 于 2016-10-16 16:49 编辑
回复 21# bailong360
简化下代码- for /l %%i in (1 1 20) do echo;%%i|(set /p n=&call set /a "1<<%%n%%"&echo;)
复制代码
跟(for /l %%i in (1 1 5) do set /p line=&call echo;%%line%%)<a.txt是类似的吧
作者: bailong360 时间: 2016-10-16 18:46
回复 22# pcl_test
原理应该是一样的,只是原以为cmd的管道是先获取了全部输出再传递给下一个程序,觉得可以动态地获取很不可思议
有进程间通信的feel
作者: CrLf 时间: 2016-10-17 01:00
本帖最后由 CrLf 于 2016-10-17 04:04 编辑
回复 23# bailong360 - dir /s \ | find "Desktop"
复制代码
你会发现包括 more、find 在内的很多第三方工具是“边下边播”的,而 for /f %%a in ('[COMMAND]') do xx 则是要等 [COMMAND] 执行完毕才会开始 do
贴吧原帖链接:http://tieba.baidu.com/p/4377042621
这方法其实并没有太大的实用性...它的价值其实在于引出几个很有趣的问题:
这些输出是被谁吃了?
用 set /p 为什么会跳行(改用 c 语言编译的 gets 或 getch 亦然)?
又为什么不是在延时之后立刻出现跳行现象,而一定是发生在延时的下下次 set /p?
以及 ping 之后为什么会得到奇怪的结果?
为什么会 :OUT 居然会停下来等待 :IN 的 pause?
奉上测试代码,有心人自然会意:- @echo off
- %1 %0 :OUT | %0 :IN
- goto %1 :eof
-
- :OUT
- set /a a+=1
- echo %a%
- title %a%
- goto :OUT
-
- :IN
- setlocal enabledelayedexpansion
- echo -----------------
- set /p input=
- echo 1:!input!
- set /p input2=
- echo 2:!input2!
- set /p input3=
- echo 3:!input3!
- set /p input4=
- echo 4:!input4! [before sleep]
- for /l %%a in (1 1 1000) do (cd .)
- set /p input5=
- echo 5:!input5! [after sleep]
- set /p input6=
- echo 6:!input6!
- set /p input7=
- echo 7:!input7!
- set /p input8=
- echo 8:!input8! [before ping]
- ping /n 1 127.1 >nul
- set /p input9=
- echo 9:!input9! [after ping]
- set /p input10=
- echo 10:!input10!
- set /p input11=
- echo 11:!input11!
- set /p input10=
- echo 12:!input12!
- set /p input10=
- echo 13:!input13! [before pause]
- pause<con
- set /p input10=
- echo 14:!input14! [after pause]
- set /p input10=
- echo 15:!input15!
- set /p input10=
- echo 16:!input16!
- pause<con
- endlocal
- goto :IN
复制代码
通过改变变量 a 的长度并观察 title 停止刷新时的值,解方程可知管道缓冲区的 BufferSize=4095,末尾必须用于存放 \0
于是前面的现象也就得到了解答——都是缓冲区惹的祸
【以下均为推测】
假设执行了一个 命令A | 命令B,在管道内发生了如下逻辑:
命令A 执行时,向缓冲区写入文本,
当缓冲区写满 4095 字节时(含回车换行),命令A 挂起,
当缓冲区被读取时,唤醒 命令A 继续执行(唤醒的过程可能会有一个耗时),
(存疑)在命令A 唤醒时,cmd 会清理一部分缓冲区(时多时少,规律不明),
当命令A 关闭时,命令B 的 stdin 为空
也就是说,跳行的原因还是一个谜
-----------------------------------------------------------------------------------
找到两篇文章,部分佐证了这个观点:
http://blog.csdn.net/qzwujiaying/article/details/6027570
http://blog.csdn.net/guang11cheng/article/details/17144907
作者: CrLf 时间: 2016-10-17 09:34
更有意思的是用不同方式同时读取 stdin,得到的内容居然是两条时间线:- #include <windows.h>
- #include <stdio.h>
- main(){
- int i=0,j=0;
- wchar_t str[8192]=L"";
- char temp[1111]="";
- for(i=0;++i;){
- Sleep(1000);
- fgetws(str,1024,stdin);
- wprintf(L"@1 %s\r\n",str);
- fgetws(str,1024,stdin);
- wprintf(L"@2 %s\r\n",str);
- system("set /p n=&call echo Batch: %n%");
- fgetws(str,1024,stdin);
- wprintf(L"@3 %s\r\n",str);
- fgetws(str,1024,stdin);
- wprintf(L"@4 %s\r\n",str);
- getch();
- }
- }
复制代码
结论:cmd 打破时空壁垒,穿越了
作者: aa77dd@163.com 时间: 2016-10-17 12:38
本帖最后由 aa77dd@163.com 于 2016-10-17 13:01 编辑
回复 24# CrLf
set /p 后面的
input10
从 12 到 16 是不是木有改呢
象是关于 cmd 的管道阻塞处理方式
Desktop App>Technologies System Services>Interprocess Communications>ipes
Pipe Functions
管道编程
The Windows Pipes Programming - windows“管道”编程 之 "匿名管道"
那个老版的 CMD 源码中有个 文件 cop.c, 包含了 4 个关于管道的函数 ePipe ,PipeErr, PipeWait, BreakPipes
文件 600+ 行, 我就贴上吧
cop.c- #include "cmd.h"
-
- extern int LastRetCode;
-
- extern int ExtCtrlc; /* @@1 */
-
- /* M000 ends */
-
- unsigned PipeCnt ; /* M007 - Active pipe count */
- struct pipedata *PdHead = NULL; /* M007 - 1st element of pipedata list */
- struct pipedata *PdTail = NULL; /* M007 - Last element of pipedata list */
- unsigned PipePid ; /* M007 - Communication with ECWork */
-
-
-
- /*** eComSep - execute a statement containing a command separator
- *
- * Purpose:
- * Execute the left and right hand sides of a command separator
- * operator.
- *
- * int eComSep(struct node *n)
- *
- * Args:
- * n - parse tree node containing the command separator node
- *
- * Returns:
- * Whatever the right hand side returns.
- *
- * Notes:
- * Revised to always supply both args to Dispatch().
- */
-
- int eComSep(n)
- struct node *n ;
- {
- Dispatch(RIO_OTHER,n->lhs) ;
- return(Dispatch(RIO_OTHER,n->rhs)) ;
- }
-
-
- /*** eOr - execute an OR operation
- *
- * Purpose:
- * Execute the left hand side of an OR operator (||). If it succeeds,
- * quit. Otherwise execute the right side of the operator.
- *
- * int eOr(struct node *n)
- *
- * Args:
- * n - parse tree node containing the OR operator node
- *
- * Returns:
- * If the left hand side succeeds, return SUCCESS. Otherwise, return
- * whatever the right side returns.
- *
- * Notes:
- * Revised to always supply both args to Dispatch().
- */
-
- int eOr(n)
- struct node *n ;
- {
- int i ; /* Retcode from L.H. side of OR */
- if ((i = Dispatch(RIO_OTHER,n->lhs)) == SUCCESS)
- return(SUCCESS) ;
- else {
- LastRetCode = i;
- return(Dispatch(RIO_OTHER,n->rhs)) ;
- }
- }
-
-
-
-
- /*** eAnd - execute an AND operation
- *
- * Purpose:
- * Execute the left hand side of an AND operator (&&). If it fails,
- * quit. Otherwise execute the right side of the operator.
- *
- * int eAnd(struct node *n)
- *
- * Args:
- * n - parse tree node containing the AND operator node
- *
- * Returns:
- * If the left hand side fails, return its return code. Otherwise, return
- * whatever the right side returns.
- *
- * Notes:
- * Revised to always supply both args to Dispatch().
- */
-
- int eAnd(n)
- struct node *n ;
- {
- int i ; /* Retcode from L.H. side of AND */
-
- if ((i = Dispatch(RIO_OTHER,n->lhs)) != SUCCESS)
- return(i) ;
- else
- return(Dispatch(RIO_OTHER,n->rhs)) ;
- }
-
-
-
-
-
- /********************* START OF SPECIFICATION **************************/
- /* */
- /* SUBROUTINE NAME: ePipe */
- /* */
- /* DESCRIPTIVE NAME: Pipe Process */
- /* */
- /* FUNCTION: Execute the left side of the pipe and direct its output to*/
- /* the right side of the pipe. */
- /* */
- /* NOTES: None */
- /* */
- /* */
- /* ENTRY POINT: ePipe */
- /* LINKAGE: NEAR */
- /* */
- /* INPUT: n - parse tree node containing the pipe operator */
- /* */
- /* OUTPUT: None */
- /* */
- /* EXIT-NORMAL: The return code of the right side process. */
- /* */
- /* EXIT-ERROR: Failure if no pipe redirection can take place. */
- /* */
- /* EFFECTS: */
- /* */
- /* struct pipedata { */
- /* unsigned rh ; Pipe read handle */
- /* unsigned wh ; Pipe write handle */
- /* unsigned shr ; Handles where the normal... */
- /* unsigned shw ; ...STDIN/OUT handles are saved */
- /* unsigned lPID ; Pipe lh side PID */
- /* unsigned rPID ; Pipe rh side PID */
- /* unsigned lstart ; Start Information of lh side @@4*/
- /* unsigned rstart ; Start Information of rh side @@4*/
- /* struct pipedata *prvpds ; Ptr to previous pipedata struct */
- /* struct pipedata *nxtpds ; Ptr to next pipedata struct */
- /* } */
- /* */
- /* unsigned PipePID; Pipe Process ID */
- /* */
- /* unsigned start_type; Start Information */
- /* */
- /* */
- /* INTERNAL REFERENCES: */
- /* ROUTINES: */
- /* PutStdErr - Print an error message */
- /* Abort - Terminate program with abort */
- /* SetList - Set Link List for pipedata structure */
- /* Cdup - Duplicate supplied handle and save the new handle*/
- /* Cdup2 - Duplicate supplied handle and save the new handle*/
- /* Dispatch - Execute the program */
- /* PipeErr - Handle pipe error */
- /* Cclose - Close the specified handle */
- /* PipeWait - Wait for the all pipe process completion */
- /* */
- /* EXTERNAL REFERENCES: */
- /* ROUTINES: */
- /* DOSMAKEPIPE - Make pipe */
- /* */
- /********************** END OF SPECIFICATION **************************/
- /*** ePipe - Create a pipeline between two processes (M000)
- *
- * Purpose:
- * Execute the left side of the pipe and direct its output to
- * the right side of the pipe.
- *
- * int ePipe(struct node *n)
- *
- * Args:
- * n - parse tree node containing the pipe operator
- *
- * Returns:
- * The return code of the right side process or failure if no
- * pipe redirection can take place.
- *
- * Notes:
- * M007 - This function has been completely rewritten for real pipes.
- *
- */
-
- int ePipe(n)
- struct node *n ;
- {
- struct pipedata *Pd ; /* Pipe struct pointer */
- int k = 0 ; /* RH side return code */
- struct node *l ; /* Copy of left side arg */
- struct node *r ; /* Copy of right side arg */
- extern unsigned start_type ; /* API type used to start */
- TCHAR cflags ; /* */
-
- l = n->lhs ; /* Equate locals to... */
- r = n->rhs ; /* ...L & R operations */
-
- DEBUG((OPGRP,PILVL,"PIPES:LH = %d, RH = %d ",l->type,r->type)) ;
-
- if (!(Pd = (struct pipedata *)mkstr(sizeof(struct pipedata)))) {
-
- DEBUG((OPGRP,PILVL,"PIPES:Couldn't alloc structure!")) ;
-
- return(FAILURE) ;
- } ;
-
- if (_pipe((int *)Pd, 0, O_BINARY)) {
-
- DEBUG((OPGRP,PILVL,"PIPES:pipe failed!")) ;
-
- PutStdErr(ERROR_NOT_ENOUGH_MEMORY, NOARGS); /* M013 */
- return(FAILURE) ;
- Abort() ;
- } ;
-
- SetList(Pd->rh) ; /* M009 */
- SetList(Pd->wh) ; /* M009 */
-
- DEBUG((OPGRP,PILVL,"PIPES:Pipe built. Handles: rd = %d wt = %d ",Pd->rh, Pd->wh)) ;
- DEBUG((OPGRP,PILVL,"PIPES:Pipe (pre-index) count = %d", PipeCnt)) ;
-
- if (!PipeCnt++) { /* Already some pipes? */
- PdHead = PdTail = Pd ; /* No, set head/tail ptrs */
- Pd->prvpds = NULL ; /* No previous structure */
-
- DEBUG((OPGRP,PILVL,"PIPES:This is first pipe.")) ;
-
- } else {
-
- DEBUG((OPGRP,PILVL,"PIPES:This is pipe %d.", PipeCnt)) ;
-
- PdTail->nxtpds = Pd ;
- Pd->prvpds = PdTail ;
- Pd->nxtpds = NULL ;
- PdTail = Pd ;
- } ;
-
- if ((Pd->shw = Cdup(STDOUT)) == BADHANDLE) { /* Save STDOUT (M009) */
- Pd->shw = BADHANDLE ; /* If err, go process it */
- PipeErr() ; /* DOES NOT RETURN */
- } ;
-
- DEBUG((OPGRP,PILVL,"PIPES:STDOUT dup'd to %d.", Pd->shw)) ;
-
- if (Cdup2(Pd->wh, STDOUT) == BADHANDLE) /* Make wh STDOUT (M009) */
- PipeErr() ; /* DOES NOT RETURN */
-
- Cclose(Pd->wh) ; /* Close pipe hndl (M009) */
- Pd->wh = 0 ; /* And zero the holder */
-
- if (l->type <= CMDTYP) /* @@5a */
- { /* @@5a */
- FindAndFix( (struct cmdnode *) l, &cflags ) ; /* @@5a */
- } /* @@5a */
-
- DEBUG((OPGRP,PILVL,"PIPES:Write pipe now STDOUT")) ;
-
- k = Dispatch(RIO_PIPE,l) ;
-
- DuplicateHandle( (HANDLE)PipePid, CRTTONT(Pd->rh),
- NULL, NULL, 0, FALSE, DUPLICATE_CLOSE_SOURCE);
-
- if (Cdup2(Pd->shw, STDOUT) == BADHANDLE) /* M009 */
- PipeErr() ; /* DOES NOT RETURN */
-
- Cclose(Pd->shw) ; /* M009 */
- Pd->shw = 0 ;
-
- DEBUG((OPGRP,PILVL,"PIPES:STDOUT now handle 1 again.")) ;
-
- if (k) {
- ExtCtrlc = 2; /* @@1 */
- Abort() ;
- }
-
- Pd->lPID = PipePid ;
- Pd->lstart = start_type ; /* Save the start_type in pipedata struct */
- PipePid = 0 ;
- start_type = NONEPGM ; /* Reset the start_type D64 */
-
- DEBUG((OPGRP,PILVL,"PIPES:Dispatch LH side succeeded - LPID = %d.",Pd->lPID)) ;
-
-
- if ((Pd->shr = Cdup(STDIN)) == BADHANDLE) { /* Save STDIN (M009) */
- Pd->shr = BADHANDLE ;
- PipeErr() ; /* DOES NOT RETURN */
- } ;
-
- DEBUG((OPGRP,PILVL,"PIPES:STDIN dup'd to %d.", Pd->shr)) ;
-
- if (Cdup2(Pd->rh, STDIN) == BADHANDLE) /* Make rh STDIN (M009) */
- PipeErr() ; /* DOES NOT RETURN */
-
- Cclose(Pd->rh) ; /* Close pipe hndl (M009) */
- Pd->rh = 0 ; /* And zero the holder */
-
- if (r->type <= CMDTYP) /* @@5a */
- { /* @@5a */
- FindAndFix( (struct cmdnode *) r, &cflags) ; /* @@5a */
- } ; /* @@5a */
-
- DEBUG((OPGRP,PILVL,"PIPES:Read pipe now STDIN")) ;
-
- k = Dispatch(RIO_PIPE,r) ;
-
- if (Cdup2(Pd->shr, STDIN) == BADHANDLE) /* M009 */
- PipeErr() ; /* DOES NOT RETURN */
-
- Cclose(Pd->shr) ; /* M009 */
- Pd->shr = 0 ;
-
- DEBUG((OPGRP,PILVL,"PIPES:STDIN now handle 0 again.")) ;
-
- if (k) {
- ExtCtrlc = 2; /* @@1 */
- Abort() ;
- }
-
- Pd->rPID = PipePid ;
- Pd->rstart = start_type ; /* Save the start_type in pipedata struct */
- PipePid = 0 ;
- start_type = NONEPGM ; /* Reset the start_type D64 */
-
- DEBUG((OPGRP,PILVL,"PIPES:Dispatch RH side succeeded - RPID = %d.",Pd->rPID)) ;
-
- if (!(--PipeCnt)) { /* Additional pipes? */
-
- DEBUG((OPGRP,PILVL,"PIPES:Returning from top level pipe. Cnt = %d", PipeCnt)) ;
-
- return(PipeWait()) ; /* No, return CWAIT */
- } ;
-
- DEBUG((OPGRP,PILVL,"PIPES:Returning from pipe. Cnt = %d", PipeCnt)) ;
-
- return(k) ; /* Else return exec ret */
- }
-
-
-
-
- /*** PipeErr - Fixup and error out following pipe error
- *
- * Purpose:
- * To provide single error out point for multiple error conditions.
- *
- * int PipeErr()
- *
- * Args:
- * None.
- *
- * Returns:
- * DOES NOT RETURN TO CALLER. Instead it causes an internal Abort().
- *
- */
-
- void PipeErr()
- {
-
- PutStdErr(MSG_PIPE_FAILURE, NOARGS) ; /* M013 */
- Abort() ;
- }
-
-
-
-
-
- /********************* START OF SPECIFICATION **************************/
- /* */
- /* SUBROUTINE NAME: PipeWait */
- /* */
- /* DESCRIPTIVE NAME: Wait and Collect Retcode for All Pipe Completion */
- /* */
- /* FUNCTION: This routine calls WaitProc or WaitTermQProc for all */
- /* pipelined processes until entire pipeline is finished. */
- /* The return code of right most element is returned. */
- /* */
- /* NOTES: If the pipelined process is started by DosExecPgm, */
- /* WaitProc is called. If the pipelined process is started */
- /* by DosStartSession, WaitTermQProc is called. */
- /* */
- /* */
- /* ENTRY POINT: PipeWait */
- /* LINKAGE: NEAR */
- /* */
- /* INPUT: None */
- /* */
- /* OUTPUT: None */
- /* */
- /* EXIT-NORMAL: No error return code */
- /* */
- /* EXIT-ERROR: Error return code from either WaitTermQProc or WaitProc*/
- /* */
- /* */
- /* EFFECTS: None. */
- /* */
- /* INTERNAL REFERENCES: */
- /* ROUTINES: */
- /* WaitProc - wait for the termination of the specified process, */
- /* its child process, and related pipelined */
- /* processes. */
- /* */
- /* WaitTermQProc - wait for the termination of the specified */
- /* session and related pipelined session. */
- /* */
- /* EXTERNAL REFERENCES: */
- /* ROUTINES: */
- /* WINCHANGESWITCHENTRY - Change switch list entry */
- /* */
- /********************** END OF SPECIFICATION **************************/
- /*** PipeWait - wait and collect retcode for all pipe completion (M007)
- *
- * Purpose:
- * To do cwaits on all pipelined processes until entire pipeline
- * is finished. The retcode of the rightmost element of the pipe
- * is returned.
- *
- * int PipeWait()
- *
- * Args:
- * None.
- *
- * Returns:
- * Retcode of rightmost pipe process.
- *
- */
-
- PipeWait()
- {
- unsigned i ;
-
- DEBUG((OPGRP,PILVL,"PIPEWAIT:Entered - PipeCnt = %d", PipeCnt)) ;
-
- while (PdHead) {
- if (PdHead->lPID) {
- DEBUG((OPGRP, PILVL, "PIPEWAIT: lPID %d, lstart %d", PdHead->lPID, PdHead->lstart));
-
- if ( PdHead->lstart == EXECPGM )
- {
- i = WaitProc(PdHead->lPID) ; /* M012 - Wait LH */
-
- DEBUG((OPGRP,PILVL,"PIPEWAIT:CWAIT on LH - Ret = %d, SPID = %d", i, PdHead->lPID)) ;
- }
- // else
- // {
- // WaitTermQProc(PdHead->lPID, &i) ;
- //
- // DEBUG((OPGRP,PILVL,"PIPEWAIT:Read TermQ on LH - Ret = %d, PID = %d", i, PdHead->lPID)) ;
- // } ;
- //
- } ;
- if (PdHead->rPID) {
- DEBUG((OPGRP, PILVL, "PIPEWAIT: rPID %d, rstart %d", PdHead->rPID, PdHead->rstart));
- if ( PdHead->rstart == EXECPGM )
- {
- i = WaitProc(PdHead->rPID) ; /* M012 - Wait RH */
-
- DEBUG((OPGRP,PILVL,"PIPEWAIT:CWAIT on RH - Ret = %d, PID = %d", i, PdHead->rPID)) ;
- }
- // else
- // {
- // WaitTermQProc(PdHead->rPID, &i) ;
- //
- // DEBUG((OPGRP,PILVL,"PIPEWAIT:Read TermQ on LH - Ret = %d, PID = %d", i, PdHead->rPID)) ;
- // } ;
-
- } ;
-
- PdHead = PdHead->nxtpds ;
- } ;
-
- DEBUG((OPGRP,PILVL,"PIPEWAIT: complete, Retcode = %d", i)) ;
-
- PdTail = NULL ; /* Cancel linked list... */
- PipeCnt = PipePid = 0 ; /* ...pipe count and pipe PID */
- LastRetCode = i;
- return(i) ;
- }
-
-
-
-
- /*** BreakPipes - disconnect all active pipes (M000)
- *
- * Purpose:
- * To remove the temporary pipe files and invalidate the pipedata
- * structure when pipes are to be terminated, either through the
- * completion of the pipe operation or SigTerm.
- *
- * This routine is called directly by the signal handler and must
- * not generate any additional error conditions.
- *
- * void BreakPipes()
- *
- * Args:
- * None.
- *
- * Returns:
- * Nothing.
- *
- * Notes:
- * M007 - This function has been completely rewritten for real pipes.
- *
- * *** W A R N I N G ! ***
- * THIS ROUTINE IS CALLED AS A PART OF SIGNAL/ABORT RECOVERY AND
- * THEREFORE MUST NOT BE ABLE TO TRIGGER ANOTHER ABORT CONDITION.
- *
- */
-
- void BreakPipes()
- {
- unsigned i ;
- struct pipedata *pnode;
-
- DEBUG((OPGRP,PILVL,"BRKPIPES:Entered - PipeCnt = %d", PipeCnt)) ;
-
- /* The following two lines have been commented out */
- /* because the NULL test on PdTail should be enough, */
- /* and more importantly, even if PipeCnt is 0, you */
- /* may still have been servicing a pipe in Pipewait */
-
- /* if (!PipeCnt) */ /* If no active pipes... */
- /* return ; */ /* ...don't do anything */
-
- pnode = PdTail;
-
- /* First, kill all of the processes */
- while (pnode) {
- if (pnode->lPID) {
- /* M012 */ i = KillProc(pnode->lPID, FALSE) ; /* Kill LH */
-
- DEBUG((OPGRP,PILVL,"BRKPIPES:LH (Pid %d) killed - Retcode = %d", PdTail->lPID, i)) ;
- } ;
-
- if (pnode->rPID) {
- /* M012 */ i = KillProc(pnode->rPID, FALSE) ; /* Kill RH */
-
- DEBUG((OPGRP,PILVL,"BRKPIPES:RH (Pid %d) killed - Retcode = %d", PdTail->rPID, i)) ;
- } ;
- pnode = pnode->prvpds ;
- }
-
- /* Wait for the processes to die, and clean up file handles */
- while (PdTail) {
- if (PdTail->lPID) {
- if (PdTail->lstart == EXECPGM) {
- i = WaitProc(PdTail->lPID);
- // } else {
- // WaitTermQProc(PdTail->lPID, &i) ;
- }
- } ;
-
- if (PdTail->rPID) {
- if (PdTail->rstart == EXECPGM) {
- i = WaitProc(PdTail->rPID);
- // } else {
- // WaitTermQProc(PdTail->rPID, &i) ;
- }
- } ;
-
- if (PdTail->rh) {
- Cclose(PdTail->rh) ; /* M009 */
-
- DEBUG((OPGRP,PILVL,"BRKPIPES:Pipe read handle closed")) ;
- } ;
- if (PdTail->wh) {
- Cclose(PdTail->wh) ; /* M009 */
-
- DEBUG((OPGRP,PILVL,"BRKPIPES:Pipe write handle closed")) ;
- } ;
- if(PdTail->shr) {
- FlushFileBuffers(CRTTONT(PdTail->shr));
- Cdup2(PdTail->shr, STDIN) ; /* M009 */
- Cclose(PdTail->shr) ; /* M009 */
-
- DEBUG((OPGRP,PILVL,"BRKPIPES:STDIN restored.")) ;
-
- } ;
- if(PdTail->shw) {
- Cdup2(PdTail->shw, STDOUT) ; /* M009 */
- Cclose(PdTail->shw) ; /* M009 */
-
- DEBUG((OPGRP,PILVL,"BRKPIPES:STDOUT restored.")) ;
-
- } ;
- PdTail = PdTail->prvpds ;
- } ;
-
- PdHead = NULL ; /* Cancel linked list... */
- PipeCnt = PipePid = 0 ; /* ...pipe count and pipe PID */
-
- DEBUG((OPGRP,PILVL,"BRKPIPES:Action complete, returning")) ;
- }
-
-
-
-
- /*** eParen - execute a parenthesized statement group
- *
- * Purpose:
- * Execute the group of statements enclosed by a statement grouping
- * operator; parenthesis().
- *
- * int eParen(struct node *n)
- *
- * Args:
- * n - parse tree node containing the PAREN operator node
- *
- * Returns:
- * Whatever the statement group returns.
- *
- * Notes:
- * M000 - Altered to always supply both args to Dispatch().
- * M004 - Debug statements were added for SILTYP operator.
- * ** WARNING **
- * BOTH THE LEFT PAREN AND THE SILENT OPERATOR (@) USE eParen
- * WHEN DISPATCHED. CHANGING ONE WILL AFFECT THE OTHER !!
- */
-
- int eParen(n)
- struct node *n ;
- {
- #ifndef NODEB
- if (n->type == PARTYP)
- DEBUG((OPGRP,PNLVL,"ePAREN: Operator is Paren")) ;
- else if (n->type == SILTYP)
- DEBUG((OPGRP,PNLVL,"ePAREN: Operator is Silent")) ;
- #endif
-
- return(Dispatch(RIO_OTHER,n->lhs)) ;
- }
复制代码
我还是去浇花来得轻松
https://play.google.com/store/ap ... m.tedrasoft.plumber
作者: Bella 时间: 2016-10-17 15:03
本帖最后由 Bella 于 2016-10-17 15:19 编辑
回复 24# CrLf - @echo off
-
- fsutil file createnew 4176B 4176 >nul
- echo 4176B
- type 4176B | cd >nul
- pause
- echo;
-
- fsutil file createnew 4177B 4177 >nul
- echo 4177B
- type 4177B | cd >nul
- pause
复制代码
作者: CrLf 时间: 2016-10-17 15:37
回复 27# Bella
这是为什么呢?
作者: aa77dd@163.com 时间: 2016-10-17 16:25
回复 28# CrLf
4176 = 4096 + 80
作者: Bella 时间: 2016-10-18 02:15
本帖最后由 Bella 于 2016-10-20 02:30 编辑
回复 28# CrLf
fsutil file createnew 这命令不错, 测试的时候有用
作者: Bella 时间: 2016-10-18 02:15
回复 26# aa77dd@163.com
我以为用树莓派浇花
作者: aa77dd@163.com 时间: 2016-10-18 02:37
本帖最后由 aa77dd@163.com 于 2016-10-18 02:43 编辑
回复 31# Bella
看了下别人的方案, 传感器, 水泵开关这些需要一些硬件接口资料, 事实上这简单的方案,
纯粹用电子电路也差不多可以实现了
纯电子电路的最简陋方案: 湿度传感器 湿度低于 干燥阀值 , 启动水泵; 湿度高于湿润阀值, 关闭水泵. 简单原理如此, 但实现上肯定会有很多细节问题要解决
我倒是想过做成个打印机, 也不是很好玩, 一直没入手
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |