none
Using system to run a fortran executable from c++ in windows

    Question

  • Hi,

    I've been trying to get a fortran executable to run from a program written in c++. I seem to be having problems with the syntax of the command. I haven't had a lot of experience with the windows/dos command line and the syntax seems to be a bit different.

    Here is what I've been trying to use:

    system("D:\\Data\\Visual Studio 2005\\Projects\\jnrWathnet\\wathnetConsole\\Debug\\wathnetConsole.exe");

    It seems to run into problems because it thinks that the command ends after Visual. If I remove the double slashes it comes up with a bunch of warnings, and runtime errors with finding the file. It still seems to think that the name of the file ends after Visual.

    Does anyone have any advice on how I should be formatting the system call?

    Cheers,

    J
    Tuesday, June 17, 2008 9:31 AM

Answers

  • You need to quote the path:

    system("\"D:\\Data\\Visual Studio 2005\\Projects\\jnrWathnet\\wathnetConsole\\Debug\\wathnetConsole.exe\"");


    David Wilkinson | Visual C++ MVP
    Tuesday, June 17, 2008 10:29 AM

All replies


  • You can start an application using ShellExecute Function


    Regards,
    Suman


    Tuesday, June 17, 2008 10:19 AM

  • Have you tried with single slash except for drive like:
    system("D:\Data\Visual Studio 2005\Projects\jnrWathnet\wathnetConsole\Debug\wathnetConsole.exe"); ?
    • Edited by rp_suman Tuesday, June 17, 2008 10:29 AM mentioned exact path
    Tuesday, June 17, 2008 10:28 AM
  • You need to quote the path:

    system("\"D:\\Data\\Visual Studio 2005\\Projects\\jnrWathnet\\wathnetConsole\\Debug\\wathnetConsole.exe\"");


    David Wilkinson | Visual C++ MVP
    Tuesday, June 17, 2008 10:29 AM
  • I think the problem I'm having may be more to do with the windows syntax of actually running the program. If I type the file path into the cmd then the program won't run either. I guess there's something that I have to do to get it to run, other than just entering the path.

    Sorry to seem daft, but could you give an example of how I would use the ShellExecute Function to run an executable?

    I'd like to think that my inability to work this out comes from my lack of experience with windows, but it might just be that I'm tired after fighting with this code all day.

    Cheers,

    J
    Tuesday, June 17, 2008 10:31 AM
  • davewilk said:

    You need to quote the path:

    system("\"D:\\Data\\Visual Studio 2005\\Projects\\jnrWathnet\\wathnetConsole\\Debug\\wathnetConsole.exe\"");


    David Wilkinson | Visual C++ MVP

    Thanks so much, that seems to have got it going. Still have errors, hopefully will be able to sort them out :-)

    Cheers,

    J

    Tuesday, June 17, 2008 10:33 AM