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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:42:07+00:00 2026-06-11T01:42:07+00:00

I try to execute a basic command,which is java -version, in java code. My

  • 0

I try to execute a basic command,which is “java -version”, in java code. My code works for the shell commands, in example “ls”, “echo $PATH” etc.
My code :

import java.io.*;

public class cmd {
    public static void main(String[] args) {

        String command = "java -version";
        Process proc = null;
        try {
            proc = Runtime.getRuntime().exec(command);
        } catch (IOException e1) {
            System.out.println( "IOException 1" );
        }

        BufferedInputStream buffer = new BufferedInputStream( proc.getInputStream() );
        BufferedReader commandOutput= new BufferedReader( new InputStreamReader( buffer ) );
        String line = null;
        try {
            while ( ( line = commandOutput.readLine() ) != null ) {
                System.out.println( line );
            }
            commandOutput.close(); 
        } catch ( IOException e) {
            System.out.println( "IOException 2" );
        }
    }
}

The code works without exception or error, but there is not an output.

If String command = “ls”, the code could be worked and the output could be seen in the console.

  • 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-11T01:42:08+00:00Added an answer on June 11, 2026 at 1:42 am

    Check .getErrorStream() and .getOutputStream() of Process object that you have. You’ll likely see an error message there telling you that you need to specify full path to java executable for this to work. However, if the reason is something different, you should see that also when outputting the contents of mentioned streams.

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

Sidebar

Related Questions

I tried to run commands using pipes. Basic : single=ls -l $single which works
When I try to execute my code, I'm getting an error dialog: 'Show Disassembly'
I get the following error when I try and execute the code down below.
I'm on ubuntu 10.04 when I try to execute a java program in a
I am testing the code below, does a basic database query. It works fine
I want to execute a bunch of commands which throw exceptions but I'm having
Using a basic Http Post example, try { // Construct data String data =
When I try to execute the below class using ICriteria, if (_userGroupId > 0
When I try to execute this statement in Oracle SQL Developer 2.1 a dialog
This is what I try to execute: CREATE TABLE order ( o_id INTEGER 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.