Enter the redirection question-Linux general technology-Linux programming and kernel information. The following is a detailed description. # Include
# Include
# Include
# Include
# Include
# Include
Int main (void )...{
Int filedes;
If (filedes = open ("dd.txt", O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR) <0)
Fprintf (stderr, "% s", "open file error ");
Close (1 );
Dup (filedes );
Close (filedes );
Execlp ("ls", "-l", (char *) 0 );
Return 0;
}
The above is the redirection of the output. I heard that the redirection of the input can only be changed to close (0), but the program prompts "read failed:-: Wrong file descriptor
"
The Code is as follows:
# Include
# Include
# Include
# Include
# Include
# Include
Int main (void )...{
Int filedes;
If (filedes = open ("dd.txt", O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR) <0)
Fprintf (stderr, "% s", "open file error ");
Close (0 );
Dup (filedes );
Close (filedes );
Execlp ("sort", "sort", (char *) 0 );
Return 0;
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service