Koz Ross
Koz Ross

Reputation: 3140

Why is my piping failing?

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?

Upvotes: 1

Views: 85

Answers (2)

mockinterface
mockinterface

Reputation: 14860

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.

Upvotes: 1

foxidrive
foxidrive

Reputation: 41224

edit.bat has no %1 parameter

You could try this:

@echo off
copy nul %1 > nul
echo %1
call edit %1

Upvotes: 0

Related Questions