Write a C Program that demonstrates redirection of standard output to a file .EX: ls > f1.
AIM:
Write a C Program that demonstrates redirection of standard output to a file .EX:ls>f1.
Program:
#include<stdlib.h> #include<stdio.h> #include<string.h> main(int argc, char *argv[]) { char d[50]; if(argc==2) { bzero(d,sizeof(d)); strcat(d,"ls "); strcat(d,"> "); strcat(d,argv[1]); system(d); } else printf("\nInvalid No. of inputs"); }
output:
student@ubuntu:~$ gcc –o std.out std.c student@ubuntu:~$ls downloads documents listing.c listing.out std.c std.out student@ubuntu:~$ cat > f1 ^z student@ubuntu:~$./std.out f1 student@ubuntu:~$cat f1 downloads documents listing.c listing.out std.c std.out
-
UpdatedJun 07, 2017
-
Views11,439
You May Like
Write a Shell script to find factorial of a given integer.
Write in C the following Unix commands using system calls A). cat B). ls C). mv
Write a Shell script that displays list of all the files in the current directory to which the user has read, Write and execute permissions.
Write a Shell script that accepts a filename, starting and ending line numbers as arguments and displays all the lines between the given line numbers.
Write a C program to emulate the Unix ls-l command.
Write a Shell script to list all of the directory files in a directory.