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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:58:49+00:00 2026-05-22T15:58:49+00:00

I’ve built this actionPerformed method so that it reads a string I pass to

  • 0

I’ve built this actionPerformed method so that it reads a string I pass to the button (I needed to make my own button class to hold this new string) and depending on what it says, it does a different action. One of the possibilities of the string is to be something like: shell(“”). This is supposed to run a system command (command line in windows, shell command in unix/linux) in the background. This is the source of the method:

public void actionPerformed(ActionEvent e) {
        if (e.getSource() == this.button) {
            if (password != "") {

            }
            if (action.startsWith("shell(\"")) {
                String tmpSHELL = action.substring(7, action.length() - 2);

                try {
                    Process p = Runtime.getRuntime().exec(tmpSHELL);
                } catch (IOException e1) {
                    ErrorDialog error = new ErrorDialog("Error handling your shell action");
                    System.exit(0);
                }

            }
            else if (action.startsWith("frame(\"")) {
                String tmpFRAME = action.substring(7, action.length() - 2);
                MenuFrame target = ConfigReader.getFrame(tmpFRAME);
                this.parent.setVisible(false);
                this.parent.validate();
                target.setVisible(true);
                target.validate();
            }
            else if (action.equals("exit()")) {
                System.exit(0);
            }
            else {
                ErrorDialog error = new ErrorDialog("You config file contains an invalid action command. Use either shell(), frame() or exit()");
                System.exit(0);
            }   
        }
    }

I know that I get into the method but I’m not sure if the command is being executed successfully. I’m currently in a windows environment so I made a simple batch script that echos some text then waits for a keystroke before printing the tree of the C: drive. I put the .bat into my working java directory and passed the string shell(“test”) (test is the name of the batch file). However, when I click the button I get an error dialog (the one I coded above).

Is there something wrong with my code or maybe my understanding of how executing a shell command works in java? The command is throwing an IO exception but I can’t seem to figure out why. Thanks in advance for your help.

Stacktrace:

java.io.IOException: Cannot run program "test": CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessBuilder.start(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at Button.actionPerformed(Button.java:52)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(Unknown Source)
    at java.lang.ProcessImpl.start(Unknown Source)
    ... 30 more
  • 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-22T15:58:50+00:00Added an answer on May 22, 2026 at 3:58 pm
    The system cannot find the file specified
    

    Your file path is not right. Try passing an absolute file path.

    shell("C:/somedirectory/test.bat")
    

    Also, you can test this by removing the string test altogether. Hard code the runtime execution of the batch file by making the if statement always true and passing the path to your batch file to the Runtime.getRuntime().exec()

             if (password != "") {
    
             }
            if (true) {
                String tmpSHELL = action.substring(7, action.length() - 2);
    
                try {
                    Process p = Runtime.getRuntime().exec("test");
                } catch (IOException e1) {
                    ErrorDialog error = new ErrorDialog("Error handling your shell action");
                    System.exit(0);
                }
    
            }
    

    This should produce the same error. Then replace the file path with an absolute file path and you should be able to execute the batch file.

    Process p = Runtime.getRuntime().exec("C:/somedirectory/test.bat");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've got a string that has curly quotes in it. I'd like to replace
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.