What is the equivalent (programmatically) of cat /dev/something > file.txt












-1















I'm copying a video from a camera stream using a command cat /dev/video0 > file.mpeg
This works perfectly, however I want too break up the file into smaller chunks... So I've been waiting pressing Ctrl+C.. Wanted to automate that so created a batch script that will wait X minutes then halt the job, meanwhile show a progress bar. Works great however I want to take it another step.. I have an XML file that contains the exact times and file names, I have a mono program that parses this file.



Here's the question.. How can I programmatically run this cat command. Sure I could execute a system command. But I was thinking of just doing the entire application in the same language. I can open a file to write as a binary write and read say 1000 bytes at a time... But what is cat doing? Does it know how much/ how fast to read somehow?










share|improve this question

























  • I think and I might be wrong, that the cat reads and outputs the file as fast as the source device, system and CPU allows.

    – Vlastimil
    2 hours ago
















-1















I'm copying a video from a camera stream using a command cat /dev/video0 > file.mpeg
This works perfectly, however I want too break up the file into smaller chunks... So I've been waiting pressing Ctrl+C.. Wanted to automate that so created a batch script that will wait X minutes then halt the job, meanwhile show a progress bar. Works great however I want to take it another step.. I have an XML file that contains the exact times and file names, I have a mono program that parses this file.



Here's the question.. How can I programmatically run this cat command. Sure I could execute a system command. But I was thinking of just doing the entire application in the same language. I can open a file to write as a binary write and read say 1000 bytes at a time... But what is cat doing? Does it know how much/ how fast to read somehow?










share|improve this question

























  • I think and I might be wrong, that the cat reads and outputs the file as fast as the source device, system and CPU allows.

    – Vlastimil
    2 hours ago














-1












-1








-1








I'm copying a video from a camera stream using a command cat /dev/video0 > file.mpeg
This works perfectly, however I want too break up the file into smaller chunks... So I've been waiting pressing Ctrl+C.. Wanted to automate that so created a batch script that will wait X minutes then halt the job, meanwhile show a progress bar. Works great however I want to take it another step.. I have an XML file that contains the exact times and file names, I have a mono program that parses this file.



Here's the question.. How can I programmatically run this cat command. Sure I could execute a system command. But I was thinking of just doing the entire application in the same language. I can open a file to write as a binary write and read say 1000 bytes at a time... But what is cat doing? Does it know how much/ how fast to read somehow?










share|improve this question
















I'm copying a video from a camera stream using a command cat /dev/video0 > file.mpeg
This works perfectly, however I want too break up the file into smaller chunks... So I've been waiting pressing Ctrl+C.. Wanted to automate that so created a batch script that will wait X minutes then halt the job, meanwhile show a progress bar. Works great however I want to take it another step.. I have an XML file that contains the exact times and file names, I have a mono program that parses this file.



Here's the question.. How can I programmatically run this cat command. Sure I could execute a system command. But I was thinking of just doing the entire application in the same language. I can open a file to write as a binary write and read say 1000 bytes at a time... But what is cat doing? Does it know how much/ how fast to read somehow?







cat io






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 4 hours ago









Jeff Schaller

39.5k1054126




39.5k1054126










asked 4 hours ago









user1529413user1529413

93




93













  • I think and I might be wrong, that the cat reads and outputs the file as fast as the source device, system and CPU allows.

    – Vlastimil
    2 hours ago



















  • I think and I might be wrong, that the cat reads and outputs the file as fast as the source device, system and CPU allows.

    – Vlastimil
    2 hours ago

















I think and I might be wrong, that the cat reads and outputs the file as fast as the source device, system and CPU allows.

– Vlastimil
2 hours ago





I think and I might be wrong, that the cat reads and outputs the file as fast as the source device, system and CPU allows.

– Vlastimil
2 hours ago










1 Answer
1






active

oldest

votes


















-1














Wait with sleep and kill cat



Since it works well enough with cat and ctrl+c, the following shellscript should work.



The cat process has the process ID pid, which is used by the kill command.



#!/bin/bash

if [ $# -ne 3 ]
then
echo "Usage: $0 <stream device> <output file> <play-time>"
exit
fi

stream="$1"
outfile="$2"
ptime="$3" # seconds

cat "$stream" > "$outfile" & pid=$!

sleep "$ptime"

kill $pid


cat is a simple tool for reading/writing data. There is no way to set the speed or time interval for the data transfer in cat. You have to control it outside cat. But there are many other tools.



Use the built-in features in ffmpeg



It is also possible to use the multimedia tool ffmpeg. There is a steep learning curve, but when you get into using it, you will find that it is a very powerful tool. There are detailed instructions in the manual man ffmpeg but it is better to search for a suitable tutorial via the internet.



Example:



I have tested the following command line with conversion from an MTS file to an mpeg file. I have not tested it from a device, but I think it will work. You may want to control the conversion (to be different from the defaults) using more options in the command line.



ffmpeg -t 5 -i /dev/video0 file.mpeg


where -t 5 means that 5 seconds are recorded.






share|improve this answer


























  • @user1529413, The community is downvoting this answer. If you find it useful, please let me know. Otherwise I will delete it (after some time for you to test it).

    – sudodus
    1 min ago











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f495392%2fwhat-is-the-equivalent-programmatically-of-cat-dev-something-file-txt%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









-1














Wait with sleep and kill cat



Since it works well enough with cat and ctrl+c, the following shellscript should work.



The cat process has the process ID pid, which is used by the kill command.



#!/bin/bash

if [ $# -ne 3 ]
then
echo "Usage: $0 <stream device> <output file> <play-time>"
exit
fi

stream="$1"
outfile="$2"
ptime="$3" # seconds

cat "$stream" > "$outfile" & pid=$!

sleep "$ptime"

kill $pid


cat is a simple tool for reading/writing data. There is no way to set the speed or time interval for the data transfer in cat. You have to control it outside cat. But there are many other tools.



Use the built-in features in ffmpeg



It is also possible to use the multimedia tool ffmpeg. There is a steep learning curve, but when you get into using it, you will find that it is a very powerful tool. There are detailed instructions in the manual man ffmpeg but it is better to search for a suitable tutorial via the internet.



Example:



I have tested the following command line with conversion from an MTS file to an mpeg file. I have not tested it from a device, but I think it will work. You may want to control the conversion (to be different from the defaults) using more options in the command line.



ffmpeg -t 5 -i /dev/video0 file.mpeg


where -t 5 means that 5 seconds are recorded.






share|improve this answer


























  • @user1529413, The community is downvoting this answer. If you find it useful, please let me know. Otherwise I will delete it (after some time for you to test it).

    – sudodus
    1 min ago
















-1














Wait with sleep and kill cat



Since it works well enough with cat and ctrl+c, the following shellscript should work.



The cat process has the process ID pid, which is used by the kill command.



#!/bin/bash

if [ $# -ne 3 ]
then
echo "Usage: $0 <stream device> <output file> <play-time>"
exit
fi

stream="$1"
outfile="$2"
ptime="$3" # seconds

cat "$stream" > "$outfile" & pid=$!

sleep "$ptime"

kill $pid


cat is a simple tool for reading/writing data. There is no way to set the speed or time interval for the data transfer in cat. You have to control it outside cat. But there are many other tools.



Use the built-in features in ffmpeg



It is also possible to use the multimedia tool ffmpeg. There is a steep learning curve, but when you get into using it, you will find that it is a very powerful tool. There are detailed instructions in the manual man ffmpeg but it is better to search for a suitable tutorial via the internet.



Example:



I have tested the following command line with conversion from an MTS file to an mpeg file. I have not tested it from a device, but I think it will work. You may want to control the conversion (to be different from the defaults) using more options in the command line.



ffmpeg -t 5 -i /dev/video0 file.mpeg


where -t 5 means that 5 seconds are recorded.






share|improve this answer


























  • @user1529413, The community is downvoting this answer. If you find it useful, please let me know. Otherwise I will delete it (after some time for you to test it).

    – sudodus
    1 min ago














-1












-1








-1







Wait with sleep and kill cat



Since it works well enough with cat and ctrl+c, the following shellscript should work.



The cat process has the process ID pid, which is used by the kill command.



#!/bin/bash

if [ $# -ne 3 ]
then
echo "Usage: $0 <stream device> <output file> <play-time>"
exit
fi

stream="$1"
outfile="$2"
ptime="$3" # seconds

cat "$stream" > "$outfile" & pid=$!

sleep "$ptime"

kill $pid


cat is a simple tool for reading/writing data. There is no way to set the speed or time interval for the data transfer in cat. You have to control it outside cat. But there are many other tools.



Use the built-in features in ffmpeg



It is also possible to use the multimedia tool ffmpeg. There is a steep learning curve, but when you get into using it, you will find that it is a very powerful tool. There are detailed instructions in the manual man ffmpeg but it is better to search for a suitable tutorial via the internet.



Example:



I have tested the following command line with conversion from an MTS file to an mpeg file. I have not tested it from a device, but I think it will work. You may want to control the conversion (to be different from the defaults) using more options in the command line.



ffmpeg -t 5 -i /dev/video0 file.mpeg


where -t 5 means that 5 seconds are recorded.






share|improve this answer















Wait with sleep and kill cat



Since it works well enough with cat and ctrl+c, the following shellscript should work.



The cat process has the process ID pid, which is used by the kill command.



#!/bin/bash

if [ $# -ne 3 ]
then
echo "Usage: $0 <stream device> <output file> <play-time>"
exit
fi

stream="$1"
outfile="$2"
ptime="$3" # seconds

cat "$stream" > "$outfile" & pid=$!

sleep "$ptime"

kill $pid


cat is a simple tool for reading/writing data. There is no way to set the speed or time interval for the data transfer in cat. You have to control it outside cat. But there are many other tools.



Use the built-in features in ffmpeg



It is also possible to use the multimedia tool ffmpeg. There is a steep learning curve, but when you get into using it, you will find that it is a very powerful tool. There are detailed instructions in the manual man ffmpeg but it is better to search for a suitable tutorial via the internet.



Example:



I have tested the following command line with conversion from an MTS file to an mpeg file. I have not tested it from a device, but I think it will work. You may want to control the conversion (to be different from the defaults) using more options in the command line.



ffmpeg -t 5 -i /dev/video0 file.mpeg


where -t 5 means that 5 seconds are recorded.







share|improve this answer














share|improve this answer



share|improve this answer








edited 15 mins ago

























answered 2 hours ago









sudodussudodus

1,30416




1,30416













  • @user1529413, The community is downvoting this answer. If you find it useful, please let me know. Otherwise I will delete it (after some time for you to test it).

    – sudodus
    1 min ago



















  • @user1529413, The community is downvoting this answer. If you find it useful, please let me know. Otherwise I will delete it (after some time for you to test it).

    – sudodus
    1 min ago

















@user1529413, The community is downvoting this answer. If you find it useful, please let me know. Otherwise I will delete it (after some time for you to test it).

– sudodus
1 min ago





@user1529413, The community is downvoting this answer. If you find it useful, please let me know. Otherwise I will delete it (after some time for you to test it).

– sudodus
1 min ago


















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f495392%2fwhat-is-the-equivalent-programmatically-of-cat-dev-something-file-txt%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Loup dans la culture

How to solve the problem of ntp “Unable to contact time server” from KDE?

ASUS Zenbook UX433/UX333 — Configure Touchpad-embedded numpad on Linux