Error on process start: The system cannot find the file specified

Error

My RhinoCommon plugin is executing an external executable. I don’t receive any error while debugging the plugin locally.

But when I push the plugin to Rhino3D server and try to download, install, and run it, I receive this error:

Finite elements…
Error on process start: The system cannot find the file specified

Code

Here is the code to execute the external executable:

        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {

            RhinoApp.WriteLine("Finite elements...");
            Helper.RunLogicWithLog("finite_elements.exe", args, runFEA);

            return Result.Success;
        }

        public static void RunLogicWithLog(string exePath, string args, PostProcess pp)
        {
            cmd = new Process();

            try
            {
                cmd.StartInfo.FileName = exePath;
                cmd.StartInfo.Arguments = args;
                cmd.StartInfo.UseShellExecute = false;
                cmd.StartInfo.CreateNoWindow = true;
                cmd.StartInfo.RedirectStandardOutput = true;
                cmd.StartInfo.RedirectStandardError = true;
                cmd.StartInfo.RedirectStandardInput = true;

                cmd.EnableRaisingEvents = true;
                cmd.OutputDataReceived += new DataReceivedEventHandler(cmd_LogReceived);
                cmd.ErrorDataReceived += new DataReceivedEventHandler(cmd_LogReceived);
                cmd.Exited += new EventHandler(cmd_Exited);
                cmd.Exited += new EventHandler(pp);

                cmd.Start();

                // Begin asynchronous log.
                cmd.BeginOutputReadLine();
                cmd.BeginErrorReadLine();
            }

            catch (Exception ex)
            {
                RhinoApp.WriteLine("Error on process start: {0}", ex.Message);
            }
        }

Executable location

I double-checked the plugin installation. I can confirm that the external executable is actually next to my plugin RHP file:

2024-01-03 03_16_49-1.0.3.0

Question

I have the external executable next to my RHP file. So, why it cannot be found?

just guessing:
StartInfo also has a WorkingDirectory
maybe check / set this ?

maybe create a full path with Reflection - see this stackoverflow article

1 Like

Hi @Megidd,

Does this help?

public class TestMegidd : Command
{
  public override string EnglishName => "TestMegidd";

  private string AppName => "finite_elements.exe";

  private string AssemblyDirectory
  {
    get
    {
      string codeBase = Assembly.GetExecutingAssembly().CodeBase;
      UriBuilder uri = new UriBuilder(codeBase);
      string path = Uri.UnescapeDataString(uri.Path);
      return Path.GetDirectoryName(path);
    }
  }

  protected override Result RunCommand(RhinoDoc doc, RunMode mode)
  {
    var dir = AssemblyDirectory;
    RhinoApp.WriteLine(dir);

    var path = Path.Combine(dir, AppName);
    RhinoApp.WriteLine(path);

    if (File.Exists(path))
    {
      // Run external process
    }

    return Result.Success;
  }
}

– Dale

1 Like