This is a follow-on question from here, posted at the suggestion of the person who originally answered it.
I'm trying to create a script that will both take piped input and also direct input from the command line. I wrote two scripts; the first is called create
and the other is called edit
. I give the code below.
@echo off
REM create
if -%1-==-- (
REM Piped
set /p name=
copy nul %name% > nul
echo %name%
) else (
REM Not piped
copy nul %1 > nul
)
@echo off
REM edit
if -%1-==-- (
REM Piped
set /p file=
start notepad++.exe %file%
) else (
REM Not piped
start notepad++.exe %1
)
I have added remarks to clarify which is which, and what my intent was. Now, the normal input (for example, if I just type create foo.txt
into the command prompt) works fine, but the moment I try piping (for example, create foo.txt | edit
) I get strange behaviour, namely, the edit script tries to open a completely different file to foo.txt
in this example! What am I missing or doing wrong?