get_command_argument

Hi there,
I am converting ifort code to PGI Community Edition 17.10 and I have a problem:
This piece of code tries to write argument#1 into cline and is doing a test print.

Compiled with : pgfortran -c -Mbackslash  test.f90
program test
character*512 cline
...
 CALL get_command_argument(1,cline,ipathexelen,istat)
  print *,'PGI CALL get_command_argument(1,cline, ) istat=',istat
  print *,TRIM(cline)

The print results are (note the odd placement of "):

PGI CALL get_command_argument(1,cline, ) istat= 0
D:\TRM\TRM23\exe" D:\TRM\Support22+Tests22+ADWiz22\Tests23\RS_ChipKit_TRACE"

while the command line in task manager looks as:

“C:\test.exe” “D:\TRM\TRM23\exe” “D:\TRM\Support22+Tests22+ADWiz22\Tests23\RS_ChipKit_TRACE” “.more.” “.more.”

I was expecting cline to be “D:\TRM\TRM23\exe”

Is it my fault or a bug?
Best regards,
Johannes

This seems to work for me.

PROGRAM test_get_command_argument
  INTEGER :: number,length,status
  CHARACTER(len=512) :: arg

  number = 0
  DO
    CALL get_command_argument(number, arg, length, status)
    IF (LEN_TRIM(arg) == 0) then
       write(6,*) "end of args"
       EXIT
    else

        write(6,*) "argument number  = ", number
        write(6,*) "arg              = ", arg
        write(6,*) "TRIM(arg)        = ", TRIM(arg)
        write(6,*) "LEN_TRIM(arg)    = ", LEN_TRIM(arg)
        write(6,*) "argument length  = ", length
        write(6,*) "Status of arg    = ", status

    number = number+1
    endif
  END DO
END PROGRAM

Compile
pgfortran -o tgca test_get_command_argument.f90

run
tgca here is a list of arguments

Hello jtull,
your and my code are correct. Try your exe with these arguments:

tgca.exe “hello1” “Hello2”
argument number = 0
arg =
tgca.exe
TRIM(arg) = tgca.exe
LEN_TRIM(arg) = 8
argument length = 8
Status of arg = 0
argument number = 1
arg =
hello1" Hello2"
TRIM(arg) = hello1" Hello2"
LEN_TRIM(arg) = 15
argument length = 15
Status of arg = 0
end of args

" is the problem.

Now that I know that " is treated as a sort of escape character and get_command_argument does work with “normal” strings I can change my exe arguments so that paths close with a letter and not .

Thanks for ideas,
Johannes

The backslash is an escape character on the command line.
Quote marks are delimiters.

Look at what this does

tgca “hello\” ““goodbye\””

so you can adjust the arguments to convey the real strings.

dave