简体   繁体   English

Linux命令 - 管道命令

[英]Linux commands - piping commands

I tried the following command find ~/dir1 *.m4a | play 我尝试了以下命令find ~/dir1 *.m4a | play find ~/dir1 *.m4a | play

Directory dir1 has exactly 1 m4a file in it and I'd like it to be played Yet I get a usage error from play. 目录dir1中只有1个m4a文件,我希望它能够播放但是我从播放中得到了一个使用错误。 Why? 为什么?

What you wrote instructs the output of the find command (an m4a file) to be send over as the input to the next command, play. 您编写的内容指示将find命令(m4a文件)的输出作为输入发送到下一个命令play。

Now, I have no idea what that play exactly is, but most likely, it's syntax is of the type: 现在,我不知道那个游戏究竟是什么,但最有可能的是,它的语法类型如下:

play filename

But what you wrote translates to: 但是你写的内容翻译成:

play < "filename"

So, what you probably want to do is use a command like xargs, which will do exactly that: 所以,你可能想要做的就是使用像xargs这样的命令,它会做到这一点:

find ~/dir1 *.m4a | xargs play

Which results in: 结果如下:

play foundfile1 foundfile2 ...

可能是玩不要使用STDIN所以你必须使用xargs

 find ~/dir1 \*.m4a |xargs play

You are trying to pipe the contents of the file into play (ie sending it in via STDIN). 您正试图将文件的内容传递给播放(即通过STDIN发送)。 As far as I can see from the play man page, it can't do this. 据我所知,从播放手册页中,它无法做到这一点。

You want to send the filename that find to play, like this: 您想要发送要播放的文件名,如下所示:

find ~/dir1 *.m4a | 找〜/ dir1 * .m4a | xargs play xargs玩

使用find -name *.mp4 -exec play {} /;

Try the other way: 尝试另一种方式:

play ~/dir1 *.m4a

If not working - check if play support m4a 如果不工作 - 检查播放是否支持m4a

or try with xargs in your pip line 或尝试使用pip行中的xargs

xargs play

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM