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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:56:40+00:00 2026-05-26T16:56:40+00:00

When i apply command command i do not get any output. How can i

  • 0

When i apply command command i do not get any output. How can i get output while using command or not both case?

public class test 
{

  public static void main(String args[])
  {
    System.out.println(
        systemtest("ifconfig | awk 'BEGIN { FS = \"\n\"; RS = \"\" } { print $1 $2 }' | sed -e 's/ .*inet addr:/,/' -e 's/ .*//'"));   

  }

  public static String systemtest(String cmds)
  {
    String value = "";
    try 
    { 
      String cmd[] = {
        "/bin/sh",
        "-c",
        cmds
      };       
      Process p=Runtime.getRuntime().exec(cmd); 
      // Try 0: here? wrong
      //p.waitFor(); 
      BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream())); 
      String line=reader.readLine(); 
      // Try 1: here?
      //p.waitFor(); 
      while(line!=null) 
      { 
        value += line + "\n";
        line=reader.readLine(); 
      } 
      // Try 2: here?
      p.waitFor(); 
    } catch(IOException e1) {

    } catch(InterruptedException e2) {

    } 

    return value;
  }
  • 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-26T16:56:41+00:00Added an answer on May 26, 2026 at 4:56 pm

    You need to read the output from the command before you call p.waitFor().

    Facts:

    • Output from an external command is delivered via an OS-level “pipe”.
    • Pipes have a limited amount of buffering.
    • If some producer process tries to write to a pipe that is “full”, the process is forced to wait until the consumer process has read some data from the pipe.

    It is not hard to see (from the above facts) that the way that you’re application is written will result in a deadlock if the external application produces more output than can fit into the pipe’s buffer (in O/S space).

    (Even if this is not the real cause of your problem this time, it could be other times. Watch out for deadlocks when reading from / writing to external processes.)

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

Sidebar

Related Questions

I want to apply an XSLT Stylesheet to an XML Document using C# and
when I apply the tag above my methods I get the error Type System.Runtime.CompilerServices.Extension
I'm using a parametized query to get records that will display as a grid
I've managed to get the Xcode leaks tool to report leaks in my command-line
I am trying to apply a thirdparty LAF to a NetBeans RCP application (not
I'm trying to zip files using the command-line utility through NSTask. pseudocode: controller: init:
Recently I came across following grep command: /usr/xpg4/bin/grep -Ff grep.txt input.txt > output.txt which
I was using svn for versioning my project and then I decided to not
Question Summary: how can I get the path to the currently active application under
I am writing a CKEditor plugin to apply a specific class to an element.

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.