Sandeep Chakraborty
Sandeep Chakraborty

Reputation: 23

ProcessBuilder not executing program correctly in java eclipse luna

I have created a program in ProcessBuilder in java. Below is the program. I have created the program in Eclipse IDE. While executing the program is showing errors.

//Demonstrate ProcessBuilder.
public class ProcessBuilder
{
    public static void main(String[] args) 
    {
        ProcessBuilder proc=new ProcessBuilder("notepad.exe","testfile");
        try
        {
            proc.start();           
        }
        catch(Exception e)
        {
            System.out.println("Error executing notepad.");
        }

        ProcessBuilder pb = new ProcessBuilder("java", "MyTest");
        try 
        {
            pb.start();
            System.out.println("Process has been started.");
        } 
        catch(IOException e)
        {
            e.printStackTrace();

        }
    }

The system is displaying the constructor ProcessBuilder is undefined. I have java 7 installed, jre 1.7 installed. Still I am unable to find the solution.

Upvotes: 0

Views: 523

Answers (3)

Sajan Chandran
Sajan Chandran

Reputation: 11487

As other suggested, the best option would be rename your class name, other option would be to

java.lang.ProcessBuilder proc=new java.lang.ProcessBuilder("notepad.exe","testfile");

and

java.lang.ProcessBuilder pb = new java.lang.ProcessBuilder("java", "MyTest");

So you are explicitly telling your javac to use ProcessBuilder from java.lang package.

Upvotes: 2

Aaron Digulla
Aaron Digulla

Reputation: 328870

Your class ProcessBuilder doesn't have a constructor ProcessBuilder(String...command). My guess is that you wanted to write a demo for java.lang.ProcessBuilder. Using the same name for the demo and the class which you try to use makes things confusing.

I suggest to rename your class to ProcessBuilderDemo. That will make java.lang.ProcessBuilder visible in the code.

Upvotes: 0

Sebastian Redl
Sebastian Redl

Reputation: 72225

You called your own class ProcessBuilder, so it hides the library class. Call your own class something else.

Upvotes: 0

Related Questions