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.

4
  • 1
    The 2nd process.StartInfo.Arguments assignment overwrites the first, did you mean += (with a space)? Commented Aug 4, 2016 at 13:28
  • 1
    And you do not call process.Start(). You only configure the process, but never run it. Commented Aug 4, 2016 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 Commented Aug 4, 2016 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. Commented Aug 4, 2016 at 13:44

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I think it was the /c that was stopping this from working. Your solution worked perfectly, thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.