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 6041509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:40:18+00:00 2026-05-23T06:40:18+00:00

I am having trouble using system() from libc on Linux. My code is this:

  • 0

I am having trouble using system() from libc on Linux. My code is this:

system( "tar zxvOf some.tar.gz fileToExtract | sed 's/some text to remove//' > output" );

std::string line;
int count = 0;
std::ifstream inputFile( "output" );
while( std::getline( input, line != NULL ) )
    ++count;

I run this snippet repeatedly and occasionally I find that count == 0 at the end of the run – no lines have been read from the file. I look at the file system and the file has the contents I would expect (greater than zero lines).

My question is should system() return when the entire command passed in has completed or does the presence of the pipe ‘|’ mean system() can return before the part of the command after the pipe is completed?

I have explicitly not used a ‘&’ to background any part of the command to system().

To further clarify I do in practice run the code snippet multiples times in parallel but the output file is a unique filename named after the thread ID and a static integer incremented per call to system(). I’m confident that the file being output to and read is unique for each call to system().

  • 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-23T06:40:19+00:00Added an answer on May 23, 2026 at 6:40 am

    According to the documentation

    The system() function shall not return until the child process has terminated.

    Perhaps capture the output of “output” when it fails and see what it is? In addition, checking the return value of system would be a good idea. One scenario is that the shell command you are running is failing and you aren’t checking the return value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble with redirecting urls using the .htaccess file. This is what my
I wrote some AES encryption code in C# and I am having trouble getting
I'm using the following code from this answer Sending email in .NET through Gmail
I'm having trouble using Simple Xml Serializer to build a Message from a complex
Im having trouble using a .NET COM in vb6, It compiles ok and I
I am using mssql and am having trouble using a subquery. The real query
I am having trouble using the attribute XPath Selector in ElementTree, which I should
I'm having trouble using the flowlayoutPanel in a C# winform application. What I basically
I'm new to development using Xcode, and am having trouble using the built-in Leaks
I am using NHibernate and Rhinomocks and having trouble testing what I want. I

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.