问题
I've been messing around with .cmd scripts, and wanted to practice piping. I wrote one script to make files, and another to edit them with Notepad++. The making script (called create.cmd) is as follows:
@echo off
copy nul %1 > nul
echo %1
And the edit script (called edit.cmd) is as follows:
@echo off
start notepad++.exe %1
Now, I wanted to try and make a file, and then pipe its output (hence the echo line) in the form of the name of the file to the edit script. So what I wrote was this:
create foo.txt | edit
However, this fails - I get an open Notepad++ window, but my newly-created file does not appear there. What am I missing or doing wrong here?
回答1:
You are not reading from the pipe in your second batch file.
For reading just one line of output from the first batch, the filename, this should suffice:
@echo off
set /p file=
start notepad.exe %file%
Otherwise check Read stdin stream in a batch file for reading multi-lined input.
回答2:
edit.bat has no %1
parameter
You could try this:
@echo off
copy nul %1 > nul
echo %1
call edit %1
来源:https://stackoverflow.com/questions/21493191/why-is-my-piping-failing