ridgerunnersjw
Posts: 28
Joined: Sat Jul 20, 2019 5:32 pm

Linux pipe command to copy

Wed Sep 04, 2019 9:17 pm

Not sure if this is the correct forum for linux questions but this looked as if it may be the closest, so here goes....Can someone please tell me how to pipe the output of a command to be copied to another directory? I am trying to copy the mp4 file into a shared directory (unsuccessfully I might add)

MP4Box -add t.h264 t.mp4 | cp ../share

thanks and please advise me what would be the most appropriate forum for shell command questions on this site

User avatar
scruss
Posts: 2472
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Linux pipe command to copy

Wed Sep 04, 2019 10:22 pm

Yeah, whatever MP4Box does, that is massively unlikely to work the way you'd want it to.

If MP4Box only prints the file name to standard output and nothing else, you could use:

Code: Select all

MP4Box -add t.h264 t.mp4 | xargs -I '{}' cp '{}'  ../share
This will fail if there's a space in the file name. There are better ways to do this without using a pipe. Are you trying to copy the created MP4 file to your share folder?
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

bjtheone
Posts: 253
Joined: Mon May 20, 2019 11:28 pm
Location: Kanata, Ontario, Canada

Re: Linux pipe command to copy

Sat Sep 07, 2019 7:19 pm

It looks like that command transforms the encoding. What does it output upon successful completion?

To clarify the pipe command "|" allows you to redirect stdout from the terminal to the input of the next command in the pipeline, For this to work the information must be provided to stdout.

Likely a better way would be to write a small bash script that finds the file, transforms the file if required to the appropriate encoding, and then copies or moves it upon success to the desired directory. More information would be very helpful.

What are you trying to do? Doe you want to do this to a bunch of files or to one file at a time? Are all the candidate files in the same place? Are they all in the same format? What does MP4Box output upon successful completion, and upon failure?

Return to “Raspbian”