Plex 2E

  • 1.  Plex C++ running .exe from command line

    Posted Jun 09, 2015 06:19 PM

    I have a need to run a Plex 7.1 C++ Client function from a 3rd party job scheduler and report back progression status messages back to the console as standard output. I am currently using the C++ cout function (I'm happy with another method if one exists).

     

    I can generate and run the executable and hold the command line session until it is complete and everything works fine except that I can find no way to report the running status of the job. The cout function executes but nothing appears in the console window.

    The cout message is not being sent from a server function but within the client C++ portion that the .exe was created from.

     

    i.e,

    Step 1 completed at dd/mm/yyyy hh:mm:ss

    Step 2 completed at dd/mm/yyyy hh:mm:ss

    Step 3 completed at dd/mm/yyyy hh:mm:ss

    ...

    Job xxxx completed at dd/mm/yyyy hh:mm:ss

     

    I have coded the C++ source code as such and it receives a text line as a parameter.

     

    #include "stdafx.h"

    #include <iostream>

    std::cout << "&(1:)\n" << std::endl;

    std::cout.flush();

     

    I have also tried changing the VC project file to define subsystem:console but still no output to the command window.

    The best that I can do at present is to write to a text file and at completion pipe this file to the console within a batch script but it is too late at completion time.

     

    Can any C++ gurus help?



  • 2.  Re: Plex C++ running .exe from command line

    Posted Jun 15, 2015 10:17 AM

    interesting. A 3rd party client invokes (Asynchronous or synchronous?) a plex winc function (no panel). While the plex function is processing you want to report back progress to to the 3rd party's console. right?

     

    I think you should consider the difference between PostMessage and SendMessage.

    Not that you are using this but it will highlight your issue and my guess you are using SendMessage where you should use PostMessage

     

    does that make sense?



  • 3.  Re: Plex C++ running .exe from command line

    Posted Jun 16, 2015 12:48 AM

    does it?

     

    I think we have to understand what we are doing wrong. Like the old adage of having a loop that is meant to count up to ten but in the end it doesn't but adds up to 11 so we minus 1 to get it to work with out understanding why it looped to eleven instead 10, just my preference.

     

    multithreading - How may i use asynchronous functions in C++? - Stack Overflow

     

    obviously it is impossible for us posters to truly see and test your problem but I would start with the above link which includes cout messages.

     

    So the messages do get there in the end?? but its like the old problem of progress bars in plex that you had to repaint if not the progress bar gets updated and repainted at the end.

     

    Does this make sense?



  • 4.  Re: Plex C++ running .exe from command line

    Posted Jun 15, 2015 11:28 AM

    Hi Steve,

     

    try running the exe from the command line piping std out to a file like this:

     

    myexe.exe >stdout.txt

     

    You should see the output from your application in the stdout.txt file then simply do a type of the stdout.txt to view it in the console.

    type stdout.txt and you are good to go.

     

    -Niels P.



  • 5.  Re: Plex C++ running .exe from command line

    Posted Jun 15, 2015 06:50 PM

    Hi Niels,

     

    I've already done that but need to get the messages as they happen and are appended to this file. Something would have to record the contents of the file and onlt write the newly appended messages.

     

    For those that are interested. The application invoked is a process automation suite, outputs to a database many sub requests to process jobs for certain SQL selection criteria. For example a 1 million row member database is processed 20k at a time. The actual outboard runtime job that runs these sub jobs can be anywhere in the network using underutilized PC servers to use the unused memory and processor in a grid fashion. For each large member set (includes all the child tables) as a large XMl document is processed by a compiled Idiom Decision Model dll which is held in a BLOB column for transportability throughout the network without the need to install on every sub processor. The product has tool to extract from a SQL compliant database to an XML document automatically.

    Using this technique we are able to validate an entire Super Fund database of 1 million members plus 23 complex member related tables and their share of 1 billion financial transactions in around 2 hours daily using 24 slave sub processes..

     

       Idiom Decision Manager Workbench Introduction.mp4 - YouTube

     

    So as you can see each actual sub job runs asynchronously and reports its status back to a central database which is what I am polling for completion messages.

     

    The 3rd party scheduler can execute my scheduled job .exe and pick up simple text from standard output for human eyeballing within that application.

     

    By the way the standard Idiom decision models are great for embedding inline into Plex applications as standalone user supplied executable sub routines that deal with complexity wonderfully.



  • 6.  Re: Plex C++ running .exe from command line

    Posted Jun 16, 2015 08:44 AM

    Plex exe programs do not have a console attached.  Windows (/SUBSYSTEM:WINDOWS)  Changing to /SUBSYSTEM:CONSOLE will not help, build will fail. It is possible to allocate or attach a Console to the Plex program. I tested this once and found that allocating a Console works, but attaching to an existing Console (Parent)  fails.

     

    I think the best solution is to write a wrapper in C# that calls the .exe and then monitor the process stdout /stderr streams and then write the messages to your central Database.

     

    Best regards

    Lorenz



  • 7.  Re: Plex C++ running .exe from command line
    Best Answer

    Posted Jun 16, 2015 01:14 PM
        class Program
        {
            static void Main(string[] args)
            {
    //          String ExeName = args[0];
              String ExeName = "C:\\Users\\Public\\Documents\\CA\\Plex\\7.1\\Tutrefer\\gen\\Debug\\TestCmd.EXE";

     

                Process p = new Process();
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.FileName = ExeName;
                p.Start();

     

                String mess;
             
                while   (!p.StandardOutput.EndOfStream)
                {
                    try
                    {
                        mess = p.StandardOutput.ReadLine();
                        Console.WriteLine(mess);
                    }
                    catch (Exception e) { }
                }
               
                p.WaitForExit();
                Console.Read();
                Environment.Exit(0);

     

            }
        }
    }


  • 8.  Re: Plex C++ running .exe from command line

    Posted Jun 16, 2015 05:38 PM

    Hi Lorenz,

     

    Thanks for the detailed reply and it is similar to the approach that we are prototyping a solution now.

     

    Cheers, Steve