I want to open installed softwares in my pc using a java program. For Example- If I want to open Microsoft Outlook using java program, how would I do it? Thanks in advance!!
            Asked
            
        
        
            Active
            
        
            Viewed 33 times
        
    -5
            
            
        - 
                    1[Running Command Line in Java](https://stackoverflow.com/questions/8496494/running-command-line-in-java) – phflack Oct 31 '17 at 20:18
1 Answers
0
            
            
        You can use Java ProcessBuilder to launch any program.
Example from this site
package com.javacodegeeks.process;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class ProcessBuilderExample {
    public static void main(String[] args) throws InterruptedException,
            IOException {
        ProcessBuilder pb = new ProcessBuilder("echo", "This is ProcessBuilder Example from JCG");
        System.out.println("Run echo command");
        Process process = pb.start();
        int errCode = process.waitFor();
        System.out.println("Echo command executed, any errors? " + (errCode == 0 ? "No" : "Yes"));
        System.out.println("Echo Output:\n" + output(process.getInputStream()));    
    }
    private static String output(InputStream inputStream) throws IOException {
        StringBuilder sb = new StringBuilder();
        BufferedReader br = null;
        try {
            br = new BufferedReader(new InputStreamReader(inputStream));
            String line = null;
            while ((line = br.readLine()) != null) {
                sb.append(line + System.getProperty("line.separator"));
            }
        } finally {
            br.close();
        }
        return sb.toString();
    }
}
 
    
    
        rohitmohta
        
- 1,001
- 13
- 22
