0

PICT generates test cases and test configurations. https://github.com/microsoft/pict

I want to run the executable pict.exe through a java program. I tried using Runtime.getRuntime.exec(), it ran without any errors but no output file was generated.

package com.test.CommandLine;

public class CommandLineTest {

    public static void main(String[] args) {
        String execPath = "resources\\pict.exe";
        String param = "resources\\CarOrderApp.txt > resources\\CarOrderApp.xls";

        runPict(execPath, param);
    }

    public static void runPict(String execPath, String param) {
        try {
            Process process = Runtime.getRuntime().exec(execPath + " " + param);
        } 
        catch (Exception e) {
            System.out.println(e.getMessage() + "\n");
            e.printStackTrace();
        }
    }
}

This is my project Structure:

enter image description here

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111
  • It's probably because the I/O redirection `>` is a bash operator that is not recognised here. – assylias Mar 06 '19 at 10:57
  • Running the same from cmd works just fine : resources\pict.exe resources\\CarOrderApp.txt > resources\\CarOrderApp.xls – Shivam Kedia Mar 06 '19 at 10:59
  • Yes, but that is because `cmd` interpretes that > char in that case. PIPING commands dont work like that when you use the exec (or ProcessBuilder, because you shouldnt use exec in the first place) – GhostCat Mar 06 '19 at 12:16

1 Answers1

2

You need to use ProcessBuilder to define output instead of using cmd > redirect operator:

String execPath = "resources\\pict.exe";
String inPath = "resources\\CarOrderApp.txt";
String outPath = "resources\\CarOrderApp.xls";

ProcessBuilder builder = new ProcessBuilder(execPath, inPath);
builder.redirectOutput(new File(outPath));
Process p = builder.start();
p.waitFor();
Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111