Topic
  • 4 replies
  • Latest Post - ‏2013-10-25T20:56:39Z by Phippsmx
Phippsmx
Phippsmx
2 Posts

Pinned topic DXL communication with other code

‏2013-10-21T20:06:42Z |

I am looking for a way to get a trigger in Doors to communicate with or run some C# code that I have written (to do some database work, messaging, and other things). It is pretty easy to go the other way (have C# initiate, run, and communicate with some DXL), but I can't seem to find a good way to do it with a trigger/DXL initiating the communication.

Ideal Methods that I can't find a way to do:

1) When trigger occurs, run an executable file directly instead of a dxl file

2) When trigger occurs, run a dxl file which then: Runs an executable file directly

3) When trigger occurs, run a dxl file which then: Sets up a socket or some type of network communication with a C# service and tells service to run

Non-Ideal methods that I can get to work but would prefer one of the above:

1) Have the trigger DXL modify a text file and have a C# service also monitoring that text file (basically text file communication)

2) Have a C# service hooking/monitoring Doors output looking for 'special output messages' that only come from the trigger DXL output.

 

Anybody have any experience/tips getting one of the above ideal methods working? Or perhaps a different approach to solving the problem?

 

Any help or tips would be appreciated! Thanks.

 

 

  • Adamarla
    Adamarla
    75 Posts
    ACCEPTED ANSWER

    Re: DXL communication with other code

    ‏2013-10-22T06:51:41Z  

    To run an exe, you are looking for:

    void system(string commandString)

    or to get returned data or/and wait for it to finish:

    int win32SystemWait_(string sCommand, string& sResult, int iWaitTime) // Undocumented

    -Adam

     

    Updated on 2013-10-22T06:52:45Z at 2013-10-22T06:52:45Z by Adamarla
  • llandale
    llandale
    3010 Posts
    ACCEPTED ANSWER

    Re: DXL communication with other code

    ‏2013-10-22T16:08:47Z  
    • Adamarla
    • ‏2013-10-22T06:51:41Z

    To run an exe, you are looking for:

    void system(string commandString)

    or to get returned data or/and wait for it to finish:

    int win32SystemWait_(string sCommand, string& sResult, int iWaitTime) // Undocumented

    -Adam

     

    Adam is correctly suggesting your Trigger issue one of those commands.  Looks like this:

    • string c_ComSpec    = getenv("COMSPEC") // looks like "c:\Windows\cmd.exe"
    • string Command = "c:/Wherever/Whatever.exe /Parameters"
    • string SysCommand = c_ComSpec " /c " Command
    • system(SysCommand)
    • sleep_(2000)    // give it 2 seconds to finish
    • proceed...

    Oddly, I cannot get the wait version to work on my system.

    -Louie

    IIRC, the Compec " /c " was for DOS commands (in my case "fc") but not needed when running an EXE.

  • pommCannelle
    pommCannelle
    81 Posts
    ACCEPTED ANSWER

    Re: DXL communication with other code

    ‏2013-10-25T12:58:24Z  
    • llandale
    • ‏2013-10-22T16:08:47Z

    Adam is correctly suggesting your Trigger issue one of those commands.  Looks like this:

    • string c_ComSpec    = getenv("COMSPEC") // looks like "c:\Windows\cmd.exe"
    • string Command = "c:/Wherever/Whatever.exe /Parameters"
    • string SysCommand = c_ComSpec " /c " Command
    • system(SysCommand)
    • sleep_(2000)    // give it 2 seconds to finish
    • proceed...

    Oddly, I cannot get the wait version to work on my system.

    -Louie

    IIRC, the Compec " /c " was for DOS commands (in my case "fc") but not needed when running an EXE.

    Hi Louie, 

    Here after an old function made to wait the end of the action launched by the system function.

    The wait_time_in_sec  value is here to put a limit to the waiting phase ...

        string command_system (string cmd, int wait_time_in_sec) {
           int wait_time_in_ms = 1000*wait_time_in_sec
           string errmsg = null
           
           // create the lock file : while it exists the command is still running
           string lockfile = tempFileName          // ( os give us a legal temp file )
           string errmsgfile = tempFileName
           Stream out = write lockfile            // create the temp file ...
           close out
           
           // make the batchfile command
           string batchfile = tempFileName ".bat"
           out = write batchfile
           out << cmd " 2> \"" errmsgfile "\"\n"    // ( error treatment )
           out << "if %errorlevel% EQU 0 del \"" errmsgfile "\"\n"
           out << "del \"" lockfile "\"\n"
           close out
           
           // run the batchfile command
           system batchfile                  // send the batchfile command to system
                 
           // Wait for the batchfile command to end
           int delay_in_ms = 0
           while (fileExists_ lockfile) {         // wait the lock file deletion
               if (delay_in_ms > wait_time_in_ms){   // ( timer )
                  // abort if delay > tempo s
                  errmsg = "Timeout ! (" wait_time_in_sec " sec)"
                  break
               }
               delay_in_ms += 100     
               sleep_(100)                      // sleep_ funcion used for 100 ms
           }
           deleteFile batchfile               // ( clean the batch file )
           
           // return error message if any
           if (null errmsg && fileExists_ errmsgfile){
              errmsg = readFile errmsgfile
           }
           deleteFile errmsgfile
           return errmsg
        }

    Have fun !

  • Adamarla
    Adamarla
    75 Posts

    Re: DXL communication with other code

    ‏2013-10-22T06:51:41Z  

    To run an exe, you are looking for:

    void system(string commandString)

    or to get returned data or/and wait for it to finish:

    int win32SystemWait_(string sCommand, string& sResult, int iWaitTime) // Undocumented

    -Adam

     

    Updated on 2013-10-22T06:52:45Z at 2013-10-22T06:52:45Z by Adamarla
  • llandale
    llandale
    3010 Posts

    Re: DXL communication with other code

    ‏2013-10-22T16:08:47Z  
    • Adamarla
    • ‏2013-10-22T06:51:41Z

    To run an exe, you are looking for:

    void system(string commandString)

    or to get returned data or/and wait for it to finish:

    int win32SystemWait_(string sCommand, string& sResult, int iWaitTime) // Undocumented

    -Adam

     

    Adam is correctly suggesting your Trigger issue one of those commands.  Looks like this:

    • string c_ComSpec    = getenv("COMSPEC") // looks like "c:\Windows\cmd.exe"
    • string Command = "c:/Wherever/Whatever.exe /Parameters"
    • string SysCommand = c_ComSpec " /c " Command
    • system(SysCommand)
    • sleep_(2000)    // give it 2 seconds to finish
    • proceed...

    Oddly, I cannot get the wait version to work on my system.

    -Louie

    IIRC, the Compec " /c " was for DOS commands (in my case "fc") but not needed when running an EXE.

  • pommCannelle
    pommCannelle
    81 Posts

    Re: DXL communication with other code

    ‏2013-10-25T12:58:24Z  
    • llandale
    • ‏2013-10-22T16:08:47Z

    Adam is correctly suggesting your Trigger issue one of those commands.  Looks like this:

    • string c_ComSpec    = getenv("COMSPEC") // looks like "c:\Windows\cmd.exe"
    • string Command = "c:/Wherever/Whatever.exe /Parameters"
    • string SysCommand = c_ComSpec " /c " Command
    • system(SysCommand)
    • sleep_(2000)    // give it 2 seconds to finish
    • proceed...

    Oddly, I cannot get the wait version to work on my system.

    -Louie

    IIRC, the Compec " /c " was for DOS commands (in my case "fc") but not needed when running an EXE.

    Hi Louie, 

    Here after an old function made to wait the end of the action launched by the system function.

    The wait_time_in_sec  value is here to put a limit to the waiting phase ...

        string command_system (string cmd, int wait_time_in_sec) {
           int wait_time_in_ms = 1000*wait_time_in_sec
           string errmsg = null
           
           // create the lock file : while it exists the command is still running
           string lockfile = tempFileName          // ( os give us a legal temp file )
           string errmsgfile = tempFileName
           Stream out = write lockfile            // create the temp file ...
           close out
           
           // make the batchfile command
           string batchfile = tempFileName ".bat"
           out = write batchfile
           out << cmd " 2> \"" errmsgfile "\"\n"    // ( error treatment )
           out << "if %errorlevel% EQU 0 del \"" errmsgfile "\"\n"
           out << "del \"" lockfile "\"\n"
           close out
           
           // run the batchfile command
           system batchfile                  // send the batchfile command to system
                 
           // Wait for the batchfile command to end
           int delay_in_ms = 0
           while (fileExists_ lockfile) {         // wait the lock file deletion
               if (delay_in_ms > wait_time_in_ms){   // ( timer )
                  // abort if delay > tempo s
                  errmsg = "Timeout ! (" wait_time_in_sec " sec)"
                  break
               }
               delay_in_ms += 100     
               sleep_(100)                      // sleep_ funcion used for 100 ms
           }
           deleteFile batchfile               // ( clean the batch file )
           
           // return error message if any
           if (null errmsg && fileExists_ errmsgfile){
              errmsg = readFile errmsgfile
           }
           deleteFile errmsgfile
           return errmsg
        }

    Have fun !

  • Phippsmx
    Phippsmx
    2 Posts

    Re: DXL communication with other code

    ‏2013-10-25T20:56:39Z  
    • Adamarla
    • ‏2013-10-22T06:51:41Z

    To run an exe, you are looking for:

    void system(string commandString)

    or to get returned data or/and wait for it to finish:

    int win32SystemWait_(string sCommand, string& sResult, int iWaitTime) // Undocumented

    -Adam

     

    Thanks for the help. Exactly what I was looking for.