Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
14 Views

Run .exe built in Visual Studio Fortran on different computer

Jump to solution

Hello,

I have a Fortran Code and I built a solution and an executable file with visual studio. The code works fine on my personal computer. I have to run the .exe file on another computer. I transferred the entire folder but when I run the program it can not find the input file.

I think that there is a problem with path because the error is:   forrtl : severe (29) file not found unit 10

 

Could anyone help me?

 

 

0 Kudos

Accepted Solutions
Highlighted
Black Belt
14 Views

This isn't due to running on

Jump to solution

This isn't due to running on a different computer.  When you run from inside Visual Studio, the "default folder" for opening files is the project folder (the folder with the .vfproj file). If you run the EXE separately, the default is the folder with the EXE. The error message should also have included the path where it was looking for the file.

--
Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran

View solution in original post

0 Kudos
13 Replies
Highlighted
Black Belt
15 Views

This isn't due to running on

Jump to solution

This isn't due to running on a different computer.  When you run from inside Visual Studio, the "default folder" for opening files is the project folder (the folder with the .vfproj file). If you run the EXE separately, the default is the folder with the EXE. The error message should also have included the path where it was looking for the file.

--
Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran

View solution in original post

0 Kudos
Highlighted
Beginner
14 Views

Quote:Steve Lionel (Ret.)

Jump to solution

Steve Lionel (Ret.) wrote:

This isn't due to running on a different computer.  When you run from inside Visual Studio, the "default folder" for opening files is the project folder (the folder with the .vfproj file). If you run the EXE separately, the default is the folder with the EXE. The error message should also have included the path where it was looking for the file.

Thank you for your answer. This is true, in fact if I want to run the code from .exe file on my computer I should move the .exe in the folder that contains  .vfproj file. Is there a way to fix this path error? I mean to choose the paths from visual studio? 

0 Kudos
Highlighted
Black Belt
14 Views

Quote:Giulio P. wrote:

Jump to solution

Giulio P. wrote:

...  if I want to run the code from .exe file on my computer I should move the .exe in the folder that contains  .vfproj file. Is there a way to fix this path error? I mean to choose the paths from visual studio? 

That is one way to go. Another is to specify the relative path or the absolute path of the EXE in the command line that is used (in VS or in a command window).  You may also move the data files to another location, or you can move both the EXE and the data files to wherever you please. What is important is to understand the concept of default directory and adhere to it when writing and running your program code.

0 Kudos
Highlighted
Beginner
14 Views

Quote:mecej4 wrote:

Jump to solution

mecej4 wrote:

Quote:

Giulio P. wrote:

 

...  if I want to run the code from .exe file on my computer I should move the .exe in the folder that contains  .vfproj file. Is there a way to fix this path error? I mean to choose the paths from visual studio? 

 

 

That is one way to go. Another is to specify the relative path or the absolute path of the EXE in the command line that is used (in VS or in a command window).  You may also move the data files to another location, or you can move both the EXE and the data files to wherever you please. What is important is to understand the concept of default directory and adhere to it when writing and running your program code.

Thank you for the answer. Moving the Input and Output folder inside the requested folder the program works. The requested folder is "C:\Users\Palama". Is it possible to set in Visual studio to build a .exe file and when I run it considers as principle directory the same folder in which it's contained?

0 Kudos
Highlighted
Black Belt
14 Views

What you ask is just one

Jump to solution

What you ask is just one version of a more general question: how to set things up so that the EXE, when run, finds itself in the environment that the user wants it to be in?

Frequently, VS provides more than one menu item whose setting changes the effective environment when your EXE runs. Intel Fortran also provides a set of ask/set functions to read and write various elements of the environment. I suggest that you experiment with these facilities and then choose the combination that you find to suit your needs best.

0 Kudos
Highlighted
Black Belt
14 Views

You can set the "Working

Jump to solution

You can set the "Working Directory" in the Visual Studio project's Debugging property page. If you set it to $(OutDir), then this will be the folder containing the EXE. If that's the way you want to have your program work, use this.

--
Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos
Highlighted
Beginner
14 Views

Quote:Steve Lionel (Ret.)

Jump to solution

Steve Lionel (Ret.) wrote:

You can set the "Working Directory" in the Visual Studio project's Debugging property page. If you set it to $(OutDir), then this will be the folder containing the EXE. If that's the way you want to have your program work, use this.

Thank you so much. 

 

0 Kudos
Highlighted
14 Views

When a program opens a file

Jump to solution

When a program opens a file with no path ("file.dat"), the directory is implied as being the "current working directory".

In Visual Studio, project property page, configuration properties, Debugging, Working Directory, you can specify a working directory of your choice. *** This will be in effect when you run the program via VS debugging.

If, after built:

a) You use Windows Explorer and double click (or click and then Open), the default working directory is set to that of the .exe.
b) You launch a CMD window, and CD to the folder of the executable, then run the executable, the working directory is set to that of the .exe.
c) You launch a CMD window, and CD to the folder that is NOT that of the executable, then run the executable by explicitly specifying the path to the executable (or having it found on PATH), the working directory that which you set with CD.
d) If you create a shortcut to the executable, then perform a Properties on the shortcut, you can specify a specific working directory (when launched via that shortcut).

In addition to the above, prior to opening files in your program, you can write code that can discover your preferred working directory, then set the current directory to that folder. See: https://msdn.microsoft.com/en-us/library/windows/desktop/bb762181.aspx

Jim Dempsey

 

0 Kudos
Highlighted
Valued Contributor II
14 Views

When you run a exe outside VS

Jump to solution

When you run a exe outside VS the "working directory" is at the mercy of windows. The behaviour changes in different windows versions and according to windows settings. For example windows can chose the working folder as being the last folder that that application used on the current instance or indeed that last time the program was used. 

You can get the path of the exe file from get_command_argument and then use this path as part of any file open activity. That covers all bases.

 

0 Kudos
Highlighted
Black Belt
14 Views

I think Andrew is mistaken

Jump to solution

I think Andrew is mistaken about this - the rules are consistent, but there are additional forces that can confuse things (especially for applications that are invoked through shortcuts, which have their own settings.) Applications can also set their own defaults.

But in the absence of these things:

  • If you run the EXE from the command line, your current default directory is used
  • If you run the EXE from Windows Explorer (double-clicking), the directory the EXE is in is used

 

--
Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos
Highlighted
Valued Contributor II
14 Views

I think I am slightly at

Jump to solution

I think I am slightly at cross purposes, if you have a windows application and use Open and Save As common dialog boxes there are indeed a complex set of platform dependant rules. The quote from MSDN below indicates what they should be be I do not believe even this is fully correct:

 

The initial directory. The algorithm for selecting the initial directory varies on different platforms.

Windows 7:

  1. If lpstrInitialDir has the same value as was passed the first time the application used an Open or Save As dialog box, the path most recently selected by the user is used as the initial directory.
  2. Otherwise, if lpstrFile contains a path, that path is the initial directory.
  3. Otherwise, if lpstrInitialDir is not NULL, it specifies the initial directory.
  4. If lpstrInitialDir is NULL and the current directory contains any files of the specified filter types, the initial directory is the current directory.
  5. Otherwise, the initial directory is the personal files directory of the current user.
  6. Otherwise, the initial directory is the Desktop folder.

Windows 2000/XP/Vista:

  1. If lpstrFile contains a path, that path is the initial directory.
  2. Otherwise, lpstrInitialDir specifies the initial directory.
  3. Otherwise, if the application has used an Open or Save As dialog box in the past, the path most recently used is selected as the initial directory. However, if an application is not run for a long time, its saved selected path is discarded.
  4. If lpstrInitialDir is NULL and the current directory contains any files of the specified filter types, the initial directory is the current directory.
  5. Otherwise, the initial directory is the personal files directory of the current user.
  6. Otherwise, the initial directory is the Desktop folder.

 

 

0 Kudos
Highlighted
Black Belt
14 Views

Ah, that's quite a different

Jump to solution

Ah, that's quite a different thing, using GetOpenFileName and GetSaveFileName. You're right that those have their own rules. The OP was asking about opening a file using Fortran I/O without specifying a path.

--
Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos
Highlighted
New Contributor I
14 Views

This has been a very useful

Jump to solution

This has been a very useful discussion on a somewhat elusive subject. From my own experience I offer the following tidbits that may prove useful in several of the above situations (my apologies if they have already been implied):

If you use the Windows API function GetOpenFilename (as I do very often), the Current Working Directory (CWD) will be changed to the directory where the file resides (not obvious that it should do that, and very often not what you want).

You can discover the CWD programmatically by using the function GETCWD (requires USE IFPORT).

You can reset the CWD using the function CHDIR (also requires USE IFPORT).

I often have to use GETCWD just prior to GetOpenFilename, and immediately follow that with CHDIR, just so I can leave the CWD unmodified.

(This message is an exercise in government acronyms, possibly as sanctioned by the DRD [Department of Redundancy Department]).

0 Kudos