Liviu wrote:Haven't followed this in any depth, but it doesn't look quite the same. The pipe closes both ends without any obvious 'exit' being typed in and/or piped through.jeb wrote:But piping do the same as the exit, as the pipe itself creates two seperate sub-tasks for each side.
The prompt disappears in the child task which is never visible.Streams 3/4 redirection is foggy enough to me that I can't even spell out what the "problem" might be, let alone solve itjeb wrote:So the pipe doesn't solve the problem this way.
I think I understand what jeb is saying. The pipe is not restoring the streams. It forces the stream manipulation to occur in a child CMD.EXE process that leaves the parent CME.EXE streams alone.
--------------------
Redirection is one wacky world
I haven't fully analyzed the results to arrive at a pattern yet. But here are some interesting test cases with results.
Code: Select all
@echo off
if "%~1" neq "" goto :test
prompt $g
cls
for /l %%n in (1 1 21) do (
del file?.stream 2>nul
echo(
echo =====================================================
cmd /c "test %%n"
echo(
for %%f in (file*) do (
echo(
echo %%f contents
echo -----------------------------
type %%f
)
)
del file?.stream 2>nul
prompt
exit /b
:test
echo on & call :test%1
echo echo to stream1
>&2 echo echo to stream2
>&3 echo echo to stream3
>&4 echo echo to stream4
exit /b
:test1
echo off
exit /b
:test2
echo off 1>file1.stream
exit /b
:test3
echo off 2>file2.stream
exit /b
:test4
echo off 3>file3.stream
exit /b
:test5
echo off 4>file4.stream
exit /b
:test6
echo off 1>file1.stream 2>file2.stream 3>file3.stream 4>file4.stream
exit /b
:test7
echo off 1>file1.stream 2>file2.stream 3>file3.stream
exit /b
:test8
echo off 2>file2.stream 3>file3.stream 4>file4.stream
exit /b
:test9
echo off 1>file1.stream 3>file3.stream 4>file4.stream
exit /b
:test10
echo off 1>file1.stream 2>file2.stream 4>file4.stream
exit /b
:test11
echo off 1>file1.stream 2>file2.stream
exit /b
:test12
echo off 1>file1.stream 3>file3.stream
exit /b
:test13
echo off 1>file1.stream 4>file4.stream
exit /b
:test14
echo off 2>file2.stream 3>file3.stream
exit /b
:test15
echo off 2>file2.stream 4>file4.stream
exit /b
:test16
echo off 3>file3.stream 4>file4.stream
exit /b
:test17
echo off 1>nul 2>nul 3>file3.stream 4>file4.stream
exit /b
:test18
echo off 1>nul 2>nul 3>file3.stream
exit /b
:test19
echo off 1>nul 2>nul 4>file4.stream
exit /b
:test20
echo off 1>nul 3>file3.stream
exit /b
:test21
echo off 2>nul 4>file4.stream
exit /b
Results:
Code: Select all
=====================================================
>echo off
echo to stream1
echo to stream2
echo to stream3
The handle could not be duplicated
during redirection of handle 1.
=====================================================
>echo off 1>file1.stream
echo to stream1
echo to stream2
echo to stream3
The handle could not be duplicated
during redirection of handle 1.
file1.stream contents
-----------------------------
=====================================================
>echo off 2>file2.stream
echo to stream1
echo to stream2
echo to stream3
The handle could not be duplicated
during redirection of handle 1.
file2.stream contents
-----------------------------
=====================================================
>echo off 3>file3.stream
echo to stream1
echo to stream2
echo to stream3
The handle could not be duplicated
during redirection of handle 1.
file3.stream contents
-----------------------------
=====================================================
>echo off 4>file4.stream
echo to stream1
echo to stream2
echo to stream3
The handle could not be duplicated
during redirection of handle 1.
file4.stream contents
-----------------------------
=====================================================
>echo off 1>file1.stream 2>file2.stream 3>file3.strea
echo to stream3
echo to stream4
file1.stream contents
-----------------------------
file2.stream contents
-----------------------------
file3.stream contents
-----------------------------
echo to stream1
file4.stream contents
-----------------------------
echo to stream2
=====================================================
>echo off 1>file1.stream 2>file2.stream 3>file3.strea
echo to stream2
echo to stream3
file1.stream contents
-----------------------------
file2.stream contents
-----------------------------
file3.stream contents
-----------------------------
echo to stream1
echo to stream4
=====================================================
>echo off 2>file2.stream 3>file3.stream 4>file4.strea
echo to stream1
echo to stream4
file2.stream contents
-----------------------------
file3.stream contents
-----------------------------
echo to stream2
file4.stream contents
-----------------------------
echo to stream3
=====================================================
>echo off 1>file1.stream 3>file3.stream 4>file4.strea
echo to stream2
echo to stream4
file1.stream contents
-----------------------------
file3.stream contents
-----------------------------
echo to stream1
file4.stream contents
-----------------------------
echo to stream3
=====================================================
>echo off 1>file1.stream 2>file2.stream 4>file4.strea
echo to stream1
echo to stream3
echo to stream4
file1.stream contents
-----------------------------
file2.stream contents
-----------------------------
file4.stream contents
-----------------------------
echo to stream2
=====================================================
>echo off 1>file1.stream 2>file2.stream
echo to stream1
echo to stream2
echo to stream3
The handle could not be duplicated
during redirection of handle 1.
file1.stream contents
-----------------------------
file2.stream contents
-----------------------------
=====================================================
>echo off 1>file1.stream 3>file3.stream
echo to stream2
echo to stream3
file1.stream contents
-----------------------------
file3.stream contents
-----------------------------
echo to stream1
echo to stream4
=====================================================
>echo off 1>file1.stream 4>file4.stream
echo to stream1
echo to stream2
echo to stream3
The handle could not be duplicated
during redirection of handle 1.
file1.stream contents
-----------------------------
file4.stream contents
-----------------------------
=====================================================
>echo off 2>file2.stream 3>file3.stream
echo to stream1
echo to stream3
echo to stream4
file2.stream contents
-----------------------------
file3.stream contents
-----------------------------
echo to stream2
=====================================================
>echo off 2>file2.stream 4>file4.stream
echo to stream1
echo to stream2
echo to stream3
The handle could not be duplicated
during redirection of handle 1.
file2.stream contents
-----------------------------
file4.stream contents
-----------------------------
=====================================================
>echo off 3>file3.stream 4>file4.stream
echo to stream1
echo to stream2
echo to stream3
The handle could not be duplicated
during redirection of handle 1.
file3.stream contents
-----------------------------
file4.stream contents
-----------------------------
=====================================================
>echo off 1>nul 2>nul 3>file3.stream 4>file4.stream
echo to stream3
echo to stream4
file3.stream contents
-----------------------------
echo to stream1
file4.stream contents
-----------------------------
echo to stream2
=====================================================
>echo off 1>nul 2>nul 3>file3.stream
echo to stream2
echo to stream3
file3.stream contents
-----------------------------
echo to stream1
echo to stream4
=====================================================
>echo off 1>nul 2>nul 4>file4.stream
echo to stream1
echo to stream3
echo to stream4
file4.stream contents
-----------------------------
echo to stream2
=====================================================
>echo off 1>nul 3>file3.stream
echo to stream2
echo to stream3
file3.stream contents
-----------------------------
echo to stream1
echo to stream4
=====================================================
>echo off 2>nul 4>file4.stream
echo to stream1
echo to stream2
echo to stream3
The handle could not be duplicated
during redirection of handle 1.
file4.stream contents
-----------------------------
Dave Benham