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

  • SEARCH
  • Home
  • 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 7999607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:33:09+00:00 2026-06-04T15:33:09+00:00

ifconfig | grep ‘inet’ is working when executed via terminal. But not via QProcess

  • 0
ifconfig | grep 'inet'

is working when executed via terminal. But not via QProcess

My sample code is

QProcess p1;
p1.start("ifconfig | grep 'inet'");
p1.waitForFinished();
QString output(p1.readAllStandardOutput());
textEdit->setText(output);

Nothing is getting displayed on textedit.

but when I use just ifconfig in start of qprocess, output is getting displayed on textedit. Did I miss any trick to construct the command ifconfig | grep 'inet' , like use \' for ' and \| for |? for special characters? but I tried that as well:(

  • 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-06-04T15:33:11+00:00Added an answer on June 4, 2026 at 3:33 pm

    QProcess executes one single process. What you are trying to do is executing a shell command, not a process. The piping of commands is a feature of your shell.

    There are three possible solutions:

    Put the command you want to be executed as an argument to sh after -c (“command”):

    QProcess sh;
    sh.start("sh", QStringList() << "-c" << "ifconfig | grep inet");
    
    sh.waitForFinished();
    QByteArray output = sh.readAll();
    sh.close();
    

    Or you could write the commands as the standard input to sh:

    QProcess sh;
    sh.start("sh");
    
    sh.write("ifconfig | grep inet");
    sh.closeWriteChannel();
    
    sh.waitForFinished();
    QByteArray output = sh.readAll();
    sh.close();
    

    Another approach which avoids sh, is to launch two QProcesses and do the piping in your code:

    QProcess ifconfig;
    QProcess grep;
    
    ifconfig.setStandardOutputProcess(&grep); // "simulates" ifconfig | grep
    
    ifconfig.start("ifconfig");
    grep.start("grep", QStringList() << "inet"); // pass arguments using QStringList
    
    grep.waitForFinished(); // grep finishes after ifconfig does
    QByteArray output = grep.readAll(); // now the output is found in the 2nd process
    ifconfig.close();
    grep.close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While I try the following: system( ifconfig -a | grep inet | sed 's/\\([
ifconfig eth1 | grep -v grep | grep bytes | awk '{print $2}' |
I am trying to parse some data from ifconfig output with sed, but I
I know there is ifconfig command that we can list network interface info. but
I'm not good at scripting but found this site so hopefully some kind people
I can not get this to return anything but null for ip. I must
ifconfig -output is somewhat messy thing to look at. When I saw the nice
I can run this command fine, with the output I want: ifconfig eth0 |
Does anyone know the code to change an android phone's eth0 IP address (InetAddress)?
I would like to write a piece of code which checks, for each network

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.