Jose Ramon
Jose Ramon

Reputation: 5384

Call an executable with dynamic arguments

I am calling an executable from my Unity project. The executable contains a function which works with timer (predefined time for example 10seconds). What I want is to change the functionality a little bit instead of running with a timer to give as an input to the .exe a boolean flag with which I ll be able to continue the execution of the executable or stop it. However to do so, I have to give a dynamic input to the .exe. Is is possible to do so? And if that is possible how can I do so, without spending much system resources?

EDIT:

void record(){

    string[] args = { path, dataDir, Date+"\\", name, surname };
    System.Diagnostics.Process.Start(execDir, String.Join(" ", args));  

}

OnGUI code:

if (GUI.Button (new Rect (150,250, 100, 50), "RECORD")) {

    record();
}

if (GUI.Button (new Rect (270,250, 100, 50), "STOP")) {

        stop_recording();

}

This function record calls an executable which wrote several stuff to binary file. I have also a Stop button in which I want to add the flag. When the button pressed the flag will be true and I want to parse that value as argument into the execDir executable.

Upvotes: 1

Views: 233

Answers (1)

Ani
Ani

Reputation: 10906

I think what you want to do is to pass commands onto a running console application, am I right?

First of all, it all depends on the executable you're running. If the executable exposes no controls other than a simple "time_to_run" command line argument or starts a new instance each time you run it and you don't have the sources of this executable or are unable to compile it, you're out of options. However, if you have access to the sources or have written it yourself, you can do many things.

Applications allow external controls in various ways.

  1. Applications can read control information from a stream (stdin, memory mapped files, named pipes, etc.) - If you have access to the source code of this executable, you can make it read any one of these sources and parse the command and execute it.
  2. Use a cross-process synchronization object like a named event to stop/start specific functionality. The names of these events can be previously agreed upon.
  3. Make the console application a singleton. While this is technically the same as 2 (to allow only one instance of itself) + 1 (to pass any new commands to the "old" app), it allows simple usage without any special programming.
  4. Use .NET remoting
  5. Use WCF

Take your pick! :)

Upvotes: 1

Related Questions