Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Programming Excercise On Any Linux OS. Need not be Ubuntu In the segment of

ID: 2247219 • Letter: C

Question

C++ Programming Excercise On Any Linux OS. Need not be Ubuntu

In the segment of this task, you are required to write a C++ program that captures and lists all the contents of the current directory in long list format by using a sub-process call. You must make use of a function to do this. You are not allowed to use execvp or friends. In your program, simply just pass the command as a string parameter to that function. Note that your code will likely not perform any error-checking, so make sure you test your commands output carefully else your executable will hang if bad output was received. Do enough error checking by validating your input and output at every stage. Your output should look something like this.

Explanation / Answer

#include <iostream>
#include <cstdlib>
using namespace std;
//declare function to execute command
void execute_command(char command[]);
int main()
{
//to list directory content we need to use ls -l command
execute_command("ls -l");
return 0;
}

void execute_command(char command[])
{
system(command);
}

-------------------------------------------------------------

//output

main                                                                                                                                                                   

total 16                                                                                                                                                                       

-rwxr-xr-x 1 43205 43205 8903 Aug 30 05:18 main                                                                                                                                

-rw-r--r-- 1 43205 43205  321 Aug 30 05:18 main.cpp                                                                                                                            

-rw-r--r-- 1 43205 43205    0 Aug 30 05:10 s

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote