1.

Solve : The handle could not be duplicated during redirection of handle 1?

Answer»

So i'm trying to WRITE a batch file that will write "0| | |#start" into a file called &%plist%.list where %plist% is a previous input.

here is what i have so far:
Code: [Select]setlocal EnableDelayedExpansion
set pg=1
set plnum=1

echo 0 ^| ^| ^|#start >>^&%plist%.list

pause

:loop
cls
title Lemomusic :: Make Playlistpg %pg%
echo q Back Page
echo.
set a=1


for /f "tokens=1-2 delims=|" %%A in ($mp3lib.txt) do (
if %%A EQU %pg%!a! echo !a! %%B
if %%A EQU %pg%!a! set /a a+=1
)
echo.
echo p Next Page
echo m Done
echo.
echo.
echo.

pause
...

I am getting an error when I get to the line 'echo 0 ^| ^| ^|#start >>^&%plist%.list' where it says 'The handle could not be duplicated during redirection of handle 1'.
I tried changing the redirect value to 2 as well as 0, but they both gave the same error. Did I miss an escape character or do I need a DIFFERENT type of redirect? Thanks in advance.Why do you want to use an ampersand for the beginning of the file name?Here is a WORKAROUND - add a leading character and then rename it after the echo statement.

Code: [Select]@echo off
set plist=abc
>>"a&%plist%.list" echo 0 ^| ^| ^|#start

ren "a&%plist%.list" "&%plist%.list"
Quote from: Squashman on OCTOBER 13, 2012, 10:42:49 PM

Why do you want to use an ampersand for the beginning of the file name?

Indeed. The ampersand is not called a "poison character" for nothing. Filenames with an ampersand (or a caret) are parsed OK when typed from the command prompt but if you try to drag-and-drop such files they need at least one space, otherwise you will find out about a long-standing bug in Windows drag and drop functionality. If a file path contains at least one space, then Windows automatically encloses the path in quotes so that it gets parsed properly. Windows should do the same thing if the file path contains & or ^, but it does not. This is true up to and including Windows 8. Also such filenames make batch processing more COMPLICATED and are usually avoided by experienced batch script writers.



I was using it for a sorting mechanistic, instead of jumping in and out of folders all the time, but any character past $ on the number line will do. ($ are my batch files.) Btw: I didn't know about the & and the command line stuff, Thanks.Quote from: Lemonilla on October 14, 2012, 08:23:59 AM
any character past $ on the number line will do. ($ are my batch files.)

A lot of people use the underscore character _



Discussion

No Comment Found