- @echo off
- set var1=
- set var2=
- rem 第一个set /p尝试从子进程的输入流里面读取1203个字符,取第一个\n之前的字符串赋值给var1
- rem 但是总共传进来的字符串太少了,所以没有什么可以留给第二个set /p了(并非子进程过早关闭神马的)
- findstr "123" %0 | cmd /v /c "set /p var1=&set var1&set /p var2=&set var2"
- rem 123456
- pause
复制代码
- @echo off
- set var3=
- set var4=
- rem 只有当传递给子进程的字符串足够第一个set /p吃饱的时候,第二个set /p才有机会取到值
- findstr "abc" %0 | cmd /v /c "set /p var3=&set var3&set /p var4=&set var4"
- rem abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij
- pause
复制代码
- @echo off
- set var5=
- set var6=
- findstr "xyz" %0 >a.txt
- rem 使用重定向的时候,文本内容是传递给整个语句块的
- rem 那个for+set /p合并文件的例子也许更加容易理解http://bbs.bathome.net/thread-13327-1-1.html
- rem 重定向不是传递给for命令本身,而是传递给整个for语句块
- rem 有Shell基础的朋友可以体会一下这个帖子http://bbs.chinaunix.net/thread-3606286-1-1.html
- (set /p var5=&set var5&set /p var6=&set var6)<a.txt
- rem uvwxyz
- pause
复制代码
|