c++ - Fixing console output for my shell program -


I am writing a program that is designed for a shell that receives the input from the user from the call and a In order to execute the child, commands must be included in the program's output at the beginning of each line, including a shell prompt, which displays the number of commands issued, such as:

  Bashell [1]: ls bashell bashell. Cpp bashell.cpp ~ myshell.c ~ bashell [2]: ls bashell bashell.cpp bashell.cpp ~ myshell.c ~  

Unfortunately, my production is having a serious problem So it looks great like this. I think it may be due to the asynchronous nature of my program. I find something like this:

  bashell [1]: LS basel [2]: Basal basal CPP basil CPP ~ meshley c. LS Basel [3]: Basil Baselable CPP Basel. CPP ~ Mitele C ~ LS Basel [4]: ​​Basil Basel CPP BaseHell CPP ~ Meshley C ~ LS Basel [5]: Basil Basel CPP BaseHell CPP ~ Myshells C ~  

LS is my input, the rest comes from the shell. As you can see, shell prompt never arrives when I type LS, it's just blank and shell prompt comes after input. I

This is the relevant code I have, I have To get inputBuffer and command log, call printShellPrompt () to print a shell prompt before calling setup (inputbuffer, arguments, and background).

  int main (zero) {char inputBuffer [MAX_LINE]; / * Buffer order entered * / to keep the integer background; / * Equal 1 if any order '& amp; * / Character * args [[MAX_LINE / 2] +1]; / * Command Line (maximum of 80) * 40 argument * / pid_t pid; // Startup Greeting Cout & lt; & Lt; "Welcome to Basil. My pin is" & lt; & Lt; Getpid () & lt; & Lt; "." & Lt; & Lt; Endl; Int command quote = 1; // To calculate the number of commands so far (1) {/ * program ends in normally within the setup / / background = 0; // printf ("basile [% d]:", command quote); // stdout; // cout & lt; & Lt; "Basil [" & lt; & Lt; CommandCount & lt; & Lt; "]:"; // cout.flush (); PrintShellPrompt (commandCount); Setup (inputBuffer, Arg, & Background); / * Get the next command / / if the built-in commands handle internally (strangulation (ARG [0], "whisper") == 0} {string whisperedPhrase; (Int i = 1; i & lt; array (args); i ++) {// change from uppercase to lowercase for each letter in the token and insert / this last whispered four letter four characters = 'A '; For (int f = 0; f & lt; strlen (args [i]); f ++) {letter = tolower (args [i] [f]); WhisperedPhrase.push_back (letter); } WhisperedPhrase.push_back (''); } Cout & lt; & Lt; WhisperedPhrase; Cout & lt; & Lt; Endl; } And if (strcmp (ARG [0], "exit") == 0} {command [] = "ps -p"; Four Pip [10]; Snprintf (pid, 10, "% d", (int) getpid ()); Dome (command, pid); Strcat (Command, "-O Paid, PPID, PCPU, PMM, ATM, User, Command"); System (order); Exit (1); } Else {/ * (1) If not, then a hair process can be cut using the fork () (2), the hair process will execvp () apply (3) if the background == 0, parents wait Will, otherwise return to setup () function * / / Separately, the filename and arguments user char * fileToRun = args [0]; // a child process pudd = fork (); If (PID & lt; 0) {cerr & lt; & Lt; "Fork failed"; Return 1; } Else if (pid == 0) // hair process {cout & lt; & Lt; Endl; Execvp (fileToRun, Args); } Else if (pid> 0 & amp; amp; amp; background & gt; = 1) // basic process {parent will wait for the child to wait (); }} CommandCount ++; // Increase command count}}  

Any ideas would be appreciated!


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -