0

I'm currently hosting OSRM locally on my machine to build a routing application. When the application starts, a bool ServiceAvailable is checked with a test query to see if the application is available and running locally. I want to be able to start the OSRM application should this bool return false. I found a StackOverflow link with a similar issue and tried to implement it, but the application doesn't load. Here's my current code:

    private void StartOSRMService()
    {
        Process process = new Process();
        process.StartInfo.WorkingDirectory = @"C:\";
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.FileName = "cmd.exe";
        process.StartInfo.Arguments = "/c cd users/james/desktop/osrm/osrm-backend/osrm_release";
        process.StartInfo.Arguments = "/c osrm-routed wales-latest.osrm";
    }

The method is ran but the service never starts. In other methods, my code breaks due to a Http.Web request error, due to the lack of the service.

Community
  • 1
  • 1
James Gould
  • 4,492
  • 2
  • 27
  • 50
  • 1
    The 2nd `process.StartInfo.Arguments` assignment overwrites the first, did you mean `+=` (with a space)? – Alex K. Aug 04 '16 at 13:28
  • 1
    And you do not call `process.Start()`. You only _configure_ the process, but never run it. – René Vogt Aug 04 '16 at 13:30
  • it looks like you're trying to run 2 commands in one go, why not change the working directory to be "c:\users/james/desktop/osrm/osrm-backend/osrm_release" and then the command would be "osrm-routed wales-latest.osrm" rather than a parameter – BugFinder Aug 04 '16 at 13:31
  • I added `process.Start()` to the end of my method and set the current working directory to the `osrm_release` directory and it's still not running the command. I altered the `osrm-routed...` to `explorer .` so it would open the current directory and nothing has happened. – James Gould Aug 04 '16 at 13:44

1 Answers1

1

You can try the following:

    private void StartOSRMService()
    {
        var startInfo = new ProcessStartInfo(@"C:\users\james\desktop\osrm\osrm-backend\osrm_release\osrm-routed.exe");
        startInfo.WorkingDirectory = @"C:\users\james\desktop\osrm\osrm-backend\osrm_release";
        startInfo.UseShellExecute = false;
        startInfo.Arguments = "wales-latest.osrm";
        Process.Start(startInfo);
    }

More info on Process.Start()

Also, based on your original StartInfo.Arguments, the "/C" tells to console to terminate after the command has been executed, thus, if the "osrm-routed" is the service that needs to run in the console, and the console is terminated, then the application itself will also terminate when the console terminates.

Riaan
  • 1,541
  • 2
  • 20
  • 31