定义一个新的句柄(到STDOUT类似) [英] Define a new handle (Similar to STDOUT)
问题描述
我看着批量重定向手柄,当我注意到了这一点:
下面是链接
有提到,拉手3-9未定义,并且可以通过程序来限定。现在,我读过有关在C#中这样做,但我想知道这在cmd中/批是可能的 - 如果它是什么是它的局限性/使用
如果这是不可能在cmd中我将如何去使用这一点,可以把它是允许输出数据到屏幕soloution,并在同一时间(这已不能是一个问题它重定向到文件同时legitametly完成)。
谢谢,蒙娜丽莎。
一个批处理文件限制为只管理两个文件:STDIN输入(SET / P)操作,STDOUT输出(ECHO等)的操作;然而,我们可以有权访问多个输入和输出文件在一个批处理文件。怎么做?在一个相对简单的方法:只需将其他文件未使用手柄(3-9),并输入用此时,相应的手柄(SET / P<&安培;#)或输出(ECHO>&安培;#)命令。 p>
下面的批处理文件合并的3输入文件的行到一个输出文件具有较大的行:
关闭@echo
SETLOCAL EnableDelayedExpansion
3'; input2.txt 4℃; input3.txt(
FOR / Fdelims =%%一中(input1.txt)做(
集线=
REM阅读来自input2.txt(和写入线从INPUT1到output.txt):
集/普线= %% A<及3
REM阅读来自input3.txt(和写入线从输入2到output.txt):
集/ p =行!行! <及4
从输入3 REM写一行到output.txt:
回声(!行!
)
)> output.txt的
同样的方法可以用于产生多个输出文件。
请参阅:几个文件访问通过标准把手
和更技术性的解释这里
I was looking at redirecting handles in batch, when I noticed this:
Here is the link
It mentions that Handle 3-9 are undefined and can be defined by a program. Now I've read about doing this in C#, but I wondered if this was possible in cmd/batch - and if it is what are its limitations/use.
If it is not possible in cmd how would I go about using this, and could it be a soloution to outputing data to the screen and redirecting it to a file at the same time (a problem which has not been able to be done legitametly at the same time).
Thanks, Mona.
A Batch file is limited to manage just two files: STDIN for input (SET /P) operations, and STDOUT for output (ECHO, etc.) operations; however, we could have access to more than one input and output files in a Batch file. How to do that? In a relatively easy way: just connect the additional files to unused handles (3-9) and use the appropiate handle in the input (SET /P <&#) or output (ECHO >&#) commands.
The Batch file below merge the lines of 3 input files into one output file with larger lines:
@echo off
setlocal EnableDelayedExpansion
3<input2.txt 4<input3.txt (
for /F "delims=" %%a in (input1.txt) do (
set line=
rem Read from input2.txt (and write line from input1 to output.txt):
set /P line=%%a <&3
rem Read from input3.txt (and write line from input2 to output.txt):
set /P line=!line! <&4
rem Write line from input3 to output.txt:
echo(!line!
)
) >output.txt
The same method may be used to generate several output files.
See: Access to SEVERAL files via Standard Handles
And a more technical explanation here
这篇关于定义一个新的句柄(到STDOUT类似)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!