Silverfrost Forums

Welcome to our forums

Small issue with get_command_argument

3 Nov 2016 8:17 #18310

In the following code, status should be returned as -1 with the following command line, but 0 is returned.

anon.exe 123456789

program anon

   integer :: k, l
   character(len=8) :: buffer
   
   call get_command_argument(1, buffer, length=l, status=k)
   
   print *, 'status = ', k,' Should be -1 but isn''t!'
   print *, 'length = ', l,' Should be 9 and is!'
   
end program anon

The character array buffer contains the correct values (first 8 characters); it is just the status that is incorrect.

I can work around this by testing the length value, but probably this should be fixed. This may be a hang-over from the early days as this error also occurs in the F2KCLI code. Later compilers nagfor, ifort, gfortran don't have this issue.

3 Nov 2016 5:29 #18312

Thanks for the feedback. The 64 bit version is OK. The 32 bit version needs to be fixed.

4 Nov 2016 10:13 #18313

This bug has now been fixed for the next release. There was also a different bug in 64 bit mode and this has also been fixed.

4 Nov 2016 11:25 #18316

Paul,

Thanks very much for looking at this.

Could you also increase the internal size limit from 256 to 260 (just another 4 characters).

This will allow the maximum file path names to be read (The maximum path in windows is MAX_PATH - 1 where MAX_PATH=260. I have allowed an additional character above).

Also the length argument seems to be the limited by the size limit, but this may be harder to fix.

See this example:

program example

   integer :: l
   
   ! String 1 bigger than the size limit (currently 256)
   character(len=257) :: arg
   
   call get_command_argument(1, arg, length=l)

   print *, arg

   print *, 'length = ', l, ' should be 257 but isn''t'
   
end program example

which I run with a batch file like this:

set path=1234567890 ... 123456X
CheckMate\Win32\anon.exe %path%

where ... is enough characters to create 257 character name

4 Nov 2016 1:42 #18318

I have increased the buffer size to 260. The other issue requires the unravelling of lots of old code. It might be simpler for us to use the code for 64 bit mode if that is working OK.

4 Nov 2016 2:42 #18319

Don't worry about the other issue.

If the limit has been increased to 260 I should be able to detect when more than 259 characters are entered, which is all I need.

Thanks again.

Please login to reply.