May 2021 1 76 Report
Java cmd Commands problem?

Here is my code, it compiles but does not execute becuase I dont see a command prompt:

import java.io.*;

public class cmdCommands

{

public static void main(String[] args) throws IOException

{

String[] shutdownCmd = new String[4];

shutdownCmd[0] = "start";

shutdownCmd[1] = "/C";

shutdownCmd[2] = "dir";

shutdownCmd[3] = "pause";

for(int i = 0; i>shutdownCmd.length;i++)

{

Process child = Runtime.getRuntime().exec(shutdownCmd[i]);

}

}

}

This is my first time with trying to use cmd commands in java.

Update:

@Ratchetr:

thx but now i get a new error:

Exception in thread "main" java.io.IOException: Cannot run program "/C": CreateProcess error=2, The system cannot find the file specified

at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)

at java.lang.Runtime.exec(Runtime.java:615)

at java.lang.Runtime.exec(Runtime.java:448)

at java.lang.Runtime.exec(Runtime.java:345)

at cmdCommands.main(cmdCommands.java:15)

Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified

at java.lang.ProcessImpl.create(Native Method)

Update 3:

@Ratchetr:

thx but now i get a new error:

Exception in thread "main" java.io.IOException: Cannot run program "/C": CreateProcess error=2, The system cannot find the file specified

at java.lang.ProcessBuilder.start(ProcessBu…

at java.lang.Runtime.exec(Runtime.java:615)

at java.lang.Runtime.exec(Runtime.java:448)

at java.lang.Runtime.exec(Runtime.java:345)

at cmdCommands.main(cmdCommands.java:15)

Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified

at java.lang.ProcessImpl.create(Native Method)

Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Answers & Comments


Helpful Social

Copyright © 2024 QUIZLS.COM - All rights reserved.