1

I have a Talend job that will open an Excel file when certain conditions are met. The Excel file has lots of VBA in it to read from SQL Server and create a document. I can run the Talend job successfully when running from Open Studio. I am now trying to schedule the job in Windows Task Scheduler that will run the Talend job every 5min to open the Excel file.

I tried using a tJava component to use the Desktop class to open the file, but that did not work.

Desktop dt = Desktop.getDesktop();
dt.open(new File("C:/Users/<username>/<filepath info>/TEST.xlsm"));

Now, I'm trying to use a tSystem component with the following command:

"cmd.exe /c start excel \"C:/Users/<username>/<filepath info>/TEST.xlsm\""

I believe it does not work due to the fact that when scheduled, it becomes a background process that has no reference to a desktop or cmd that it can run the command on. How can I open my Excel file from a background job using Java?

Ted
  • 487
  • 2
  • 12
  • 23

1 Answers1

0

If using the start command and the path of the file to be started contains a space then you must specified a title to the start command.

import java.io.IOException;

    class StartExcel {
        public static void main(String args[])
            throws IOException
        {
            String fileName = "c:\\temp\\xls\\test2.xls";
            String[] commands = {"cmd", "/c", "start", "\"DummyTitle\"",fileName};
            Runtime.getRuntime().exec(commands);
        }
    }

It's feature.

RealHowTo
  • 34,977
  • 11
  • 70
  • 85