IMDb Rate Viewer is a powerful and reliable application for searching and viewing movie information from IMDb. It allows you to view movies and TV shows according to different criteria, such as Genre, Language, Country and even the cast and crew.
IMDb Rate Viewer Rating:
out of

How to find the file descriptor of stdout and stderr in C?

I’m trying to capture the output of a shell command into a file (not just a buffer, but a real file). What I have so far is
int fd = open(« MyFile.txt », O_WRONLY | O_CREAT | O_TRUNC, 0666);
char buffer[4096];

int nRead;
while (1) {
nRead = read(0, buffer, 4096);
// Do something with the buffer

This works fine, but the problem is that if the program outputs any errors (via stderr), the read() in the while loop will fail and the program will never catch the errors.
Is there a way to find out what the current file descriptor is of stdout and stderr? I would then like to try to read to fd 1 for stdout and 2 for stderr.
I have looked into dup2, but this only seems to work for stdin/stdout.


If you want to use the return value of read() instead of a special file descriptor, call it in a pipe:
int error_fd = open(« MyFile.txt », O_WRONLY | O_CREAT | O_TRUNC, 0666);
int out_fd = dup(error_fd);

int nRead;
while ((nRead = read(0, buffer, 4096)) > 0)
// Do something with the buffer

The idea is that the read() function will return an error if the read will not be successful (i.e. when read returns 0 and you have reached the end of the file). So the loop will be exited when the read() function fails.
If you want to read and write to the same file, the usage is even simpler:
int error_fd = open(« MyFile.txt », O_WRONLY | O_CREAT | O_TR eea19f52d2

Allows you to store multiple clipboard items and copy them back to the clipboard. You can also edit and replace the text in one or multiple items.
Contains the following features:
1. Create and edit multiple clipboard items.
2. Copy items to the clipboard.
3. Edit the text of multiple clipboard items.
4. Find and replace text in multiple clipboard items.
5. ‘Copy to Clipboard’ hotkey.
6. ‘Save Clipboard Set’ hotkey.
7. Edit text in multiple items.
8. Delete items from the clipboard.
9. Rename items.
10. Find and Replace multiple items.
11. Reset clipboard item.
12. Delete multiple items.
13. Delete selected items.
14. Paste multiple items.
15. Paste clipboard item.
16. Delete or undo multiple items.
17. Hide items from the list.
18. Show items from the list.
19. Order items by type.
20. Automatically backup the clipboard every 10 minutes.
21. Setting Windows version information.

…share the new experience and recommended a few word, a four students are now, at least in some of the four way. It is a powerful and if you have a low literacy rate of young people and some are born with a particular learning deficit, or, yes, if you want to help it, you can always take the certification exam to be certified.
So, if you are thinking of changing your last…

…be redirected here for the results. Thank you. The program is designed to help you add that touch of sophistication to your company image that the competition is already giving thanks to higher prices. It is an excellent opportunity to improve your marketing strategy and increase your sales. If you are not pleased with the product, we’ll refund the…

We are now offering White Label Hosting to our customers. The white label hosting is powered by Kinsta. No data and no control panel, just add your logo, choose the hosting package, customize and go live within a few seconds.
More details can be viewed on our White Label Hosting page:

You can choose…

…Social Media Management Company provides professional social media management services to small and medium businesses and organizations. Over 15 years of combined industry experience with clients ranging from $10,000 – $1,000,000

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Scroll to top