Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 在重定向到同一文件时划界Std Out和Std Err转储_Windows_Batch File - Fatal编程技术网

Windows 在重定向到同一文件时划界Std Out和Std Err转储

Windows 在重定向到同一文件时划界Std Out和Std Err转储,windows,batch-file,Windows,Batch File,这:command>file.txt 2>&1是否可以更改为在每个流中预先添加一些“header”(并可能附加一些“tail”)文本 例如,“file.txt”将读取: [标准输出]你好,世界![/std_输出] [std_错误]崩溃![/std\u错误] 编辑:需要注意的是,此操作应仅涉及写入单个文件(即,不应涉及其他临时文件)。写操作最好是原子式的,尽管也可以通过多个命令进行多个写操作,这些命令可以组合成一个命令 >file.txt echo [std_output] >temp

这:
command>file.txt 2>&1
是否可以更改为在每个流中预先添加一些“header”(并可能附加一些“tail”)文本

例如,“file.txt”将读取:

[标准输出]你好,世界![/std_输出]

[std_错误]崩溃![/std\u错误]

编辑:需要注意的是,此操作应仅涉及写入单个文件(即,不应涉及其他临时文件)。写操作最好是原子式的,尽管也可以通过多个命令进行多个写操作,这些命令可以组合成一个命令

>file.txt echo [std_output]
>tempfile.txt echo [std_error]
command >>file.txt 2>>tempfile.txt
>>file.txt echo [/std_output]
>>tempfile.txt echo [/std_error]
type tempfile.txt >>file.txt
del tempfile.txt

这可能是一个解决办法。它很简单,我不必解释了。

你能单独处理吗?(即稍后添加头部和尾部)请注意,
command>file.txt 2>&1
可能会交错使用stdout和stderr..@GerhardBarnard,这不是这里的问题
command>file.txt 2>&1
可以很好地获得out和error,而不会一个覆盖另一个。问题是以这样一种方式对它们进行分离/分隔,以便以后能够对它们进行解析。很抱歉在原始问题中没有明确说明,但我认为很明显,我试图避免使用多个临时文件。如果可能的话,我需要这是一个包含一个输出文件的单个原子命令。消息可能以任何顺序出现(我理解的问题是,应该保持顺序)。