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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:09:40+00:00 2026-05-28T22:09:40+00:00

I am attempting to get output of a shell / bash script, that is

  • 0

I am attempting to get output of a shell / bash script, that is run from a JAVA program, although I am not having much luck, the code is as follows:

GetStats(winhostname);

public static String winhostname "cmd /c hostname";

public static void GetStats(String operation)
    {
         try 
            { 
            Process p=Runtime.getRuntime().exec(operation); 
            p.waitFor(); 
            BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream())); 
            String line=reader.readLine(); 
            while(line!=null) 
            { 
            System.out.println(line);
            if (operation.equals("winhostname"))
            {
                winhostnamevalue = line;
            }
            line=reader.readLine(); 
            } 

            } 
            catch(IOException e1) {} 
            catch(InterruptedException e2) {}       
    }

This works on Windows fine, so I changed the value of winhostname to “sh namecheck.sh” (which simply echos the hostname) and the shell script is located in the same directory as the java / class file. Although when run I get a blank result, not null, just blank.

  • 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-28T22:09:40+00:00Added an answer on May 28, 2026 at 10:09 pm

    Try /bin/sh. I do not sure that when you are running program from java it has all environment that you have when you are working with shell.

    If it does not work try to run some command (e.g. pwd). But provide full path. Then, when it works try your command again and be sure that it can find your script. For the beginning use absolute path. Then move to relative path.

    Good luck.

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

Sidebar

Related Questions

I am attempting to get some information from a website, the info that I
In attempting to run ./manage.py runserver or shell or any other command for that
I am attempting to get the information from one table (games) and count the
I'm currently attempting to write my own program that mirrors the pmap command, specifically
I am attempting to make a simple shell program, and looking at a few
I'm attempting to make a php script that can load the current weather forecast
I have this: (65.94647177615738, 87.890625)(47.040182144806664, 90)(45.089035564831036, 122.34375) I'm attempting to get the output to
I'm attempting to get the allocation granularity size using GetSystemInfo() from a C# 3.5
I'm attempting to get a few user-input parameters from the console, two strings, two
I am attempting to create a php script that can connect thru ssh to

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.