0

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.

3 Answers 3

2

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.

0
0

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

0

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.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.