0

I Kofax Total Agility I created a C# basic script that calls an external java application by creating a process and passing a string parameter.

When exciting this specific part of the process I want to set a value to an output variable for example : sp.InputVariables["[Document.Status]"].

How can I set a conditional value depending on the Process or send back a value with Java ?

Here is my C# code :

using System;
using System.Diagnostics;
using System.IO;

using Agility.Server.Scripting.ScriptAssembly;

namespace MyNamespace
{

 public class Class1
 {
  public Class1() 
  {
  }

  [StartMethodAttribute()] 
  public void Method1(ScriptParameters sp) 
  {
string parameter =sp.InputVariables["[Facture.InstanceID]"].ToString();
Console.WriteLine("Parameter " + parameter);
            using (Process process = new Process())
            {
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.FileName = "java";
                process.StartInfo.Arguments = @"-jar C:\\jars\\application.jar " + parameter;
                process.Start();
                StreamReader reader = process.StandardOutput;
                string output = reader.ReadToEnd();
                process.WaitForExit();
            }
  }
 }
}
davidvera
  • 1,292
  • 2
  • 24
  • 55
  • 1
    This is a very unconventional way of doing things, and you may need to dwelve into Windows Messages, alter your Java program to use it, and your C# program to retrieve the message... This is a lot of work, while you could just write to a text file with your Java Program, then read it with the C# one before deleting the file. Also, as much as it makes me nostalgic seeing mentions of Kofax software, I hardly see how Total Agility has anything to do with your issue :) – Kilazur Jan 24 '20 at 11:43
  • Surely unconventional, but I have technical and technological constraints. It's always a real pain to make communicate applications that use different languages. I think i found out the solution with creating output variables... I'm going to try this. Thanks – davidvera Jan 24 '20 at 13:45

1 Answers1

0

I think I found out ... I'm going to test the following code. I created a pattern for formatting the response and I use output variables for defining the values of the response.

using System;
using System.Diagnostics;
using System.IO;

using Agility.Server.Scripting.ScriptAssembly;

namespace MyNamespace
{

    public class Class1
    {
      public Class1() 
      {
      }

      [StartMethodAttribute()] 
      public void Method1(ScriptParameters sp) 
      {
          string pattern = @"\|";
          string parameter =sp.InputVariables["[Facture.InstanceID]"].ToString();
          using (Process process = new Process())
          {
              process.StartInfo.UseShellExecute = false;
              process.StartInfo.RedirectStandardOutput = true;
              process.StartInfo.FileName = "java";
              process.StartInfo.Arguments = @"-jar C:\\jars\\application.jar " + parameter;
              process.Start();
              StreamReader reader = process.StandardOutput;
              string output = reader.ReadToEnd();
              process.WaitForExit();

              string[] results = Regex.Split(output, pattern, RegexOptions.IgnoreCase);

              sp.OutputVariables["responseCode"] = results[0];
              sp.OutputVariables["statusCode"] = results[1];
          }
      }
   }
}
davidvera
  • 1,292
  • 2
  • 24
  • 55