为什么我的管道失效? [英] Why is my piping failing?

查看:176
本文介绍了为什么我的管道失效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在搞乱.cmd脚本,想练习管道。我写了一个脚本来创建文件,另一个用Notepad ++编辑它们。制作脚本(称为create.cmd)如下:

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

编辑脚本(称为edit.cmd)如下:

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

但是,这会失败 - 我得到一个打开的Notepad ++窗口,但我新创建的文件出现在那里。我在这里失踪或做错了什么?

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?

推荐答案

您不是从第二个批处理文件中读取管道。

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%

在批处理文件中读取stdin流以读取多线输入。

这篇关于为什么我的管道失效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆