Example #1
0
        protected void RunJava(int JobKey, string JobFileName, string RawJobFileName)
        {
            String args = String.Format("-s {0} -d {1} JobKey={2} DefinitionFile={3}", MiscUtilities.WrapSpaces(_SettingsFile), MiscUtilities.WrapSpaces(JobFileName), JobKey, RawJobFileName);

            using (Process clientProcess = new Process())
            {
                clientProcess.StartInfo.UseShellExecute        = false;
                clientProcess.StartInfo.RedirectStandardOutput = true;
                clientProcess.StartInfo.RedirectStandardError  = true;
                clientProcess.StartInfo.CreateNoWindow         = true;
                clientProcess.StartInfo.WorkingDirectory       = MiscUtilities.AppParentPath();
                clientProcess.StartInfo.FileName  = MiscUtilities.WrapSpaces(_JavaHome + "java.exe");
                clientProcess.StartInfo.Arguments = @"-jar " + MiscUtilities.WrapSpaces(_JarPath) + " " + args;
                lock (_lock)
                {
                    LocalLog.AddLine(String.Format("Command line: {0} {1}", MiscUtilities.WrapSpaces(_JavaHome + "java.exe"), @"-jar " + MiscUtilities.WrapSpaces(_JarPath) + " " + args));
                }
                clientProcess.Start();
                string output      = clientProcess.StandardOutput.ReadToEnd();
                string errorOutput = clientProcess.StandardError.ReadToEnd();
                clientProcess.WaitForExit();
                int exitcode = clientProcess.ExitCode;
                LocalLog.AddLine("Console Output: " + System.Environment.NewLine + output);
                if (exitcode > 0)
                {
                    LocalLog.AddLine("ERROR OUTPUT: " + System.Environment.NewLine + errorOutput);
                    throw new Exception(String.Format("Run JAVA error ExitCode {0} running {1} {2}", exitcode, clientProcess.StartInfo.FileName, clientProcess.StartInfo.Arguments));
                }
            }
        }