Question by Matthew: How do I use cmd commands in java?
I want to enter this in my java program:

“net user Matthew”

and have it executed like it would in command prompt.

Best answer:

Answer by Dan B
I think the command you are looking for is

System.execute(“c:\dosomething.bat”);

I should add that I think this forks a new process rather than blocking and waiting for the result of the System.execute to return.

What do you think? Answer below!

2 thoughts on “How do I use cmd commands in java?”

  1. YOU CAN TRY THIS :

    public class Test
    {
    public static void main(String[]args)
    {
    try
    {
    Runtime.getRuntime().exec(“net user Matthew”);
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }
    }
    }

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.