Question

In: Computer Science

C programming in Shell Implement a MS-DOS style pipe command. Make sure it allows for command-line...

C programming in Shell

Implement a MS-DOS style pipe command. Make sure it allows for command-line arguments to be passed to the programs. You only need to support one pipe command at a time. For example, when you type ls | wc the shell should

  • write the output of ls to a temporary file by redirecting standard output when running ls, and
  • run wc, redirecting standard input so it reads from the temporary file written to by ls.

Solutions

Expert Solution

Here is the C code for you:

#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
#include <stdlib.h>

int main (void) {

   char command[20];
   printf("Enter your command: ");
   fgets(command, 80, stdin);   /* Read a command as input from keyboard */
   system(command);       /* Execute the command */

}

And the sample output screenshot is:

This code works for any shell commands you execute directly in terminal.


Related Solutions

I have written code in C programming that checks where the command line arguments are floats...
I have written code in C programming that checks where the command line arguments are floats or not. For example, if I type "./math 1 1 0 0 2.5 3" in the terminal, my program realizes they are all floats but if I type "./math 1 1 0 0 2.5 g", it recognizes that not all arguments are floats and gives an error message. I want to take my code further such that after typing in "./math 1 1 0...
The Programming Language is C++ PLEASE, Make sure to read the requirements and grading criteria for...
The Programming Language is C++ PLEASE, Make sure to read the requirements and grading criteria for homework first... Thank you!!! Objective: The purpose of this project is to expose you to: One-dimensional parallel arrays, input/output, Manipulating summation, maintenance of array elements. In addition, defining an array type and passing arrays and array elements to functions. Problem Specification: Using the structured chart below, write a program to keep records and print statistical analysis for a class of students. There are three...
How do I add additional command line arguments in C++? I am working on a programming...
How do I add additional command line arguments in C++? I am working on a programming assignment that has the user input a file into the command line and then they have the option to also add a series of other arguments to the command line. I know how to accept the text file from the command line by using: int main(int argc, char *argv[]) { /.../ } Then filename(argv[1]) would be the text file that they put into the...
In C programming using C11 library, how can we validate command line arguments? meaning for example...
In C programming using C11 library, how can we validate command line arguments? meaning for example if we input "./math 65 45 2.3 1 0 68" into the terminal, how can we validate that the numbers "65 45 2.3 1 0 68" are floats and not chars? In other terms the program should display and error message if the command line arguments are not floats and if they are floats, the program carries on as usual.
LINUX In Linux command line write a shell script ex1.sh that uses IF THEN to Prompt...
LINUX In Linux command line write a shell script ex1.sh that uses IF THEN to Prompt the user to "Enter a number between 1 and 10". (Hint: Use the 'echo' and 'read' commands in the script. See the slide about the 'read' command) If the number is less than 5, print "The number is less than 5" (Hint: You will read input into a variable; e.g. read NUM. In the IF statement, enclose $NUM in quotes; e.g. "$NUM". Also, remember...
You are provided with a StackInterface to implement your stack, make sure to implement the data...
You are provided with a StackInterface to implement your stack, make sure to implement the data structure using java.util.ArrayList and naming your implementation ArrayListStack (make sure to use generics like you have been for the data structures so far). The provided StackTester assumes you name your implementation that way. Note that you have also been provided a PalindromeTester with the specific isPalindrome() method you are required to implement, following the approach above. The method should take whitespace, case-sensitivity, digits, and...
Make a modification of the program below, that will read in the string as a “command-line...
Make a modification of the program below, that will read in the string as a “command-line argument” to your program, instead of having the user type it while your program is running. Your program should print out the inverted string to the screen. #include <iostream> #include <cstring> using namespace std; int Reverse(char * destination, const char * source, int num); int main() // this is the test/driver code, for your function { const int STRINGSIZE = 10; char oldCString[] =...
Systems Programming in Linux using C Remake the version of the ls -ialR command in C.....
Systems Programming in Linux using C Remake the version of the ls -ialR command in C.. In this version of ls, you must also consider symbolic file types. Make sure you have file header comments and function header comments. Also, write inline comments whenever necessary.
write a bash shell program named L1 as follows . L1 expects exactly 2 command line...
write a bash shell program named L1 as follows . L1 expects exactly 2 command line arguments. expects $1 to contain only digits. expects $2 to have exactly 4 characters (can be any character). if NOT exactly 2 command line arguments, echo "need 2 args " and exit. otherwise, if $1 and/or $2 have incorrect value(s) (as above), echo "bad argX", where X is the first incorrect argument, and exit. otherwise, echo "good ". you can use echo,grep, pipe to...
Building a Command Line Interpreter (myshell) 1.Goal of this programming assignment The primary goal of this...
Building a Command Line Interpreter (myshell) 1.Goal of this programming assignment The primary goal of this assignment is to understand and gain some familiarity with the system call interface in Unix Environment. In this assignment you will be implementing your own command line interpreter like a Unix shell program. YOU ARE NOT IMPLEMENTING COMMANDS! YOUR program should just FORK off programs and EXECUTE them. 2. Requirements (1) Programming language: You have to use either C or C++ to develop your...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT