Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29231 Discussions

How tostart debugging an .EXE that needs a command line argument

Anthony_Richards
New Contributor I
2,492 Views

If a program requires one or more command line arguments, how do you do start to debug it within the Visual Studio environment?

0 Kudos
9 Replies
Steven_L_Intel1
Employee
2,492 Views

Debugging > Command Arguments project property.

0 Kudos
Brian_Francis
Beginner
2,492 Views

Hi Steve,

I've tried this but my command arguments are being ignored. I am using VS 2015 and Fortran 16. My application calls the NT function GetCommandLine(). The return value is the executable file name only.

Previously this was working with VS 2010 and Fortran 12. The return value from GetCommandLine() is the executable file name and command arguments.

Brian.

 

0 Kudos
Anthony_Richards
New Contributor I
2,492 Views

I use

    CALL GET_COMMAND_ARGUMENT(1,DATAFILENAME,LENFILE,STATUS)

Where the '1' refers to the first argument after the command itself (the latter being obtained using '0').
The argument goes into character string 'DATAFILENAME'  and its length into integer LENFILE.
Any STATUS>0 is a failure.

Confusingly, if you need to run the release version with a command line argument, you have to do what Steve says under project properties again, but this time for the 'release' version. It's confusing that you have to select the 'debugging' option under the 'release' version, since you expect and get no debugging with it when you run it from Visual studio by selecting 'Start without debugging'.

 

0 Kudos
Steven_L_Intel1
Employee
2,492 Views

As with all the property pages, the default is to apply changes to the current configuration only. If you want it to apply to all configurations (and/or all platforms), you have to say so using the dropdowns at the top of the property page.

My guess is that Anthony is on the right track in suggesting you need to add the arguments for the current configuration.

0 Kudos
Paul_Curtis
Valued Contributor I
2,492 Views

this works very well:

!    command-line arguments
nargs = IARGC()
IF (nargs > 0) THEN
    DO j = 1, nargs
        CALL GetArg (j, argbuf, status)
        IF (status <= 0) EXIT
        IF (INDEX(argbuf, '-whatever') > 0) !set your flag
        ! and so forth
    END DO
END IF


 

0 Kudos
Steven_L_Intel1
Employee
2,492 Views

I would very strongly recommend using the Fortran standard intrinsics GET_COMMAND, GET_COMMAND_ARGUMENT and COMMAND_ARGUMENT_COUNT. There is no need to use nonstandard library routines that may have different behaviors on different platforms.

0 Kudos
Brian_Francis
Beginner
2,492 Views

A couple of short points...

1. The debug properties are set correctly. It's not pilot error (as far as I can tell, but I've been wrong before).

2. There appears to be many ways to get command line arguments, as suggested by Steve, Anthony and Paul. Diversity is good.

3. One of the ways to get command line arguments that used to work no longer does so when run against a Fortran console application from within VS 2015 (no issues though when run from a Windows shell). Unexpected loss of functionality is bad.

4. Command line processing is handled by a utility library in a common way for all our products (C, C++ and Fortran), which is why we use the NT GetCommandLine() function. I don't live in a Fortran-only universe.

Brian.

0 Kudos
andrew_4619
Honored Contributor III
2,492 Views

I suggest to run a quick test on GET_COMMAND_ARGUMENT to ensure it is not GetCommandLine(). that is broken... 

0 Kudos
IanH
Honored Contributor III
2,492 Views

Brian Francis wrote:

A couple of short points...

1. The debug properties are set correctly. It's not pilot error (as far as I can tell, but I've been wrong before).

...

3. One of the ways to get command line arguments that used to work no longer does so when run against a Fortran console application from within VS 2015 (no issues though when run from a Windows shell). Unexpected loss of functionality is bad.

Things work for me here.  Check your #1 again, making sure that the configuration that you are modifying is the configuration that you are running (the mapping between solution and project configuration is set via Build > Configuration Manager).

0 Kudos
Reply