0

I'm trying to run windows commands by using java code, but code is not working and giving exception error. Following is the code

import java.io.*; 

public class run_command
{ 
    public static void main(String args[]) 
    { 
       try  
       {
         String command = "start firefox";
         Process process = Runtime.getRuntime().exec(command);
        }
        catch(IOException e){ System.out.println(e); }
    }
}

And following is the exception error

java.io.IOException: Cannot run program "start firefox": Create Process error=2, The system cannot find the file specified.

This error is occurring for every windows commands. Please suggest some solution on this. thanks.

1 Answer 1

1

You have to run program start with parameter firefox:

Process process = Runtime.getRuntime().exec("start", "firefox");

start is an executable, so is firefox, but there is no such executable named start firefox.

Sign up to request clarification or add additional context in comments.

3 Comments

but I've also tried with command set path="{PATH}" but its not working its giving same error that is 'Cannot run program "set"'
@Omkar set is an internal command, you have to call it using cmd set.
I’m pretty sure start is built into cmd and is not an executable. Where is it located on your system?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.