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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:39:02+00:00 2026-06-09T02:39:02+00:00

I’ve found this topic, but the code doesn’t work for me… Return Windows cmd

  • 0

I’ve found this topic, but the code doesn’t work for me… Return Windows cmd text from Java?

After pressing a button I want to execute a batch-file, for testing purposes it’s just the ipconfig-command.

The cmd-output should be written into a JTextFiled, but all I get is no text…

Here the code for writing it into the JTextField:

btnLock.addActionListener(new ActionListener() 
    {
        public void actionPerformed(ActionEvent e) 
        {       
            String g = "";
            try {
                Runtime.getRuntime().exec(new String[] {"ipconfig", g});
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }  
            Process p = null;
            try {
                p = Runtime.getRuntime().exec(new String[] {"ipconfig", g});
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            InputStream s = p.getInputStream();

            BufferedReader in = new BufferedReader(new InputStreamReader(s));
            String temp;

            try {
                while ((temp = in.readLine()) != null) 
                {
                    System.out.println(temp);
                }
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }

    });
    btnLock.setBounds(10, 68, 89, 23);
    contentPane.add(btnLock);

So what do I do wrong?

It’s my first project with cmd-input, so please don’t get mad cause of silly mistakes I made. 😉

Thx

  • 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-09T02:39:03+00:00Added an answer on June 9, 2026 at 2:39 am

    Try the exec command that just takes a String parameter. The following test code worked on my system (though I was only printing to console, not to textfield):

    BufferedReader in = null;
    try{
        Process p = Runtime.getRuntime().exec("ipconfig");
        InputStream s = p.getInputStream();
    
        in = new BufferedReader(new InputStreamReader(s));
        String temp;
    
        while ((temp = in.readLine()) != null) {
            System.out.println(temp);
        }
    } catch (Exception e){
        e.printStackTrace();
    } finally {
        if (in != null) in.close();
    }
    

    Also your code in the original post is also using a System.out.println. As far as I’m aware, you can’t print to a JTextField using System.out.println…. You’d have to use the setText method.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but

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.