Answers for "java command line"

2

java run system command

Runtime.getRuntime().exec(cmdAttribs);
Posted by: Guest on September-06-2021
1

java run cmd

public void excCommand(String new_dir){
    Runtime rt = Runtime.getRuntime();
    try {
        rt.exec(new String[]{"cmd.exe","/c","start"});

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Posted by: Guest on July-05-2021
3

java command line arguments

class CommandLineExample{  
public static void main(String args[]){  
System.out.println("Your first argument is: "+args[0]);  
}  
}

//Now follow these steps
compile by > javac CommandLineExample.java  
run by > java CommandLineExample sonoo
Posted by: Guest on March-15-2020
1

command line arguments in java

public class CommandLine {
   public static void main(String args[]) {
      for(int i = 0; i<args.length; i++) {
         System.out.println("args[" + i + "]: " + args[i]);
      }
   }
}
Posted by: Guest on April-30-2020
0

how to make java run terminal commands

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ExecuteShellCommandRuntimeExec {
	public static void main (String [] args) {
		try {
			Process process = Runtime.getRuntime().exec("ls -l"); 
			
			StringBuilder output = new StringBuilder(); 
			
			BufferedReader reader = new BufferedReader(new InputStreamReader (process.getInputStream()));
			
			String line;
			
			while((line = reader.readLine()) != null) {
				output.append(line + "\n");
			}
			
			int exitVal = process.waitFor();
			if (exitVal == 0) {
				System.out.println("Success");
				System.out.println(output);
				System.exit(0);
			} else {
				System.out.println("Something abnormal has haapened :( ");
			}
				
		} catch (IOException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
Posted by: Guest on October-26-2021

Code answers related to "java command line"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language