I'm building a tool which should convert from format A to format B via Windows command prompt. I programmed something like an interactive mode. The cmd waits for input commands and process them. Now I wanted to pass some args if I call the progam. The args will be passed but the program won't execute the commands by itself.
I'm passing args like this:
java -jar test.jar -interactive //activates the interactive mode, which does not make any problems
and like this (passing the source file, the target place to save the converted file, the target format and finally the config file used during conversion):
java -jar test.jar C:\Users\User\Desktop\test.json C:\Users\User\Desktop .xes C:\Users\User\Desktop\test.properties
code so far:
public static void main(final String[] args) throws IOException, InterruptedException {
if (args[0].equals("-interactive")) {
testing test = new testing();
test.startCMD();
} else if (args[0] != null && args[1] != null && args[2] != null && args[3] != null) {
final testing test = new testing();
test.startCMD();
//the following construct doesn't work unfortunatelly
worker = Executors.newSingleThreadScheduledExecutor();
Runnable task = new Runnable() {
@Override
public void run() {
test.setSourceFile(args[0]);
test.setTargetPath(args[1]);
test.setTargetFormat(args[2]);
test.setConfigFilePath(args[3]);
System.out.println("Invoking the conversion routine now ...");
ConverterControl control = new ConverterControl();
control.link(sourceFilePath, targetPath, configFilePath, targetFormat, fileConfig);
}
};
worker.schedule(task, 5, TimeUnit.SECONDS);
}
}
public void startCMD() throws IOException, InterruptedException {
String[] command
= {
"cmd",};
Process p = Runtime.getRuntime().exec(command);
new Thread(new SyncPipe(p.getErrorStream(), System.err)).start();
new Thread(new SyncPipe(p.getInputStream(), System.out)).start();
BufferedReader in = new BufferedReader(
new InputStreamReader(System.in));
System.out.println("Welcome to the Windows command line prompt." + System.lineSeparator());
System.out.println("Please type \"help\" to receive a list of commands available in this environment.");
//String s = in.readLine();
String input;
while ((input = in.readLine()) != null) {
//process the inputs
}
The different setter you see in the main method just set the passed information to a variable which is declared at the top of the class. And afterwards these variables should be passed to ConverterControl which has the whole conversion routine in its link() method.
The program stops if I do pass 4 arguments (see second call of the program at the top) after executing the startCMD() command.
Does anyone know how to invoke these methods and start ConverterControl automatically?