Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4125810
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:55:06+00:00 2026-05-20T23:55:06+00:00

I am attempting to make a simple shell program, and looking at a few

  • 0

I am attempting to make a simple shell program, and looking at a few examples have seen that most people use getline() to get input, however I have been trying to use read() and noticed a weird bug that I was wondering if other people saw or knew the cause of.

When I run the code using getline, everything works fine. After running the program I get the terminal name to show up and it is ready to accept input. When I use read it seems to be executing the name of the shell after taking in input. This seems to occur no matter what I do. the line to display the shell name is

cout << "SweetShell-> ";

and then AFTER this line I either run the read command, or even call another process which then runs the read command, and either way printing “SweetShell-> ” happens AFTER the input.

Even weirder during testing I had a block of code like:

cout << "SweetShell-> ";
int test = read(0,buf,MAX_ARGS);
//temp is a string that is set to the input
cout << temp << "    " << test;

and the output looked something like this:

    3SweetShell-> ls

meaning it printed the spaces, then test, then the first cout, and finally temp. Anyone have any idea what is going on with this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T23:55:07+00:00Added an answer on May 20, 2026 at 11:55 pm

    You should try “flushing” the output buffer to make sure it prints in order. Try:

    cout << "SweetShell-> " << std::flush;
    int test = read(0,buf,MAX_ARGS);
    //temp is a string that is set to the input
    cout << temp << "    " << test << std::flush;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to make a simple homebrew game engine/framework in android. I have the
I am attempting to make a simple class that serializes itself to disk when
I am attempting to make a simple connection to a remote database. I can
I'm attempting to make a very simple 2-person chatroom for my Django site. I'm
I'm attempting to make a dynamic drop down that will be filled by a
I am attempting to make use of the Twisted.Web framework. Notice the three line
Attempting to print out a list of values from 2 different variables that are
In attempting to use the Performance Tools on an ASP.NET website I'm getting various
A make script is attempting to set a variable as follows: VER_DEC=$( perl -e
I'm attempting to make a chromed cube in GLUT / OpenGL and I'm not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.