- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to read stdin in a CGI program being run by an Apache server, written in Fortran, called with POST and I have tried various forms of READ(* but cannot read even the first character. But IFPORT function getC works a charm! So my questions:
What is it that getC does?
Can I do the same from standard Fortran, and if so, how?
Thanks in anticipation
N
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Fortran formatted READ is record-oriented, and wants a record with a line terminator. You should be able to get what you want if you open the file ACCESS='STREAM', FORM='UNFORMATTED' and read into a character variable (with an unformatted READ).
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
How were you calling "read"?
Note: you may find the following interesting as a reference: http://flibs.sourceforge.net/fortran-fastcgi-nginx.html
I haven't tried it myself, but it looks similar, to what you are trying to do.
Thank you,
--Eugene
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The web server is Apache in the form of XAMPP, straight out of the box on Windows 10
I have been able to read environment variable correctly, so I am sure POST was 'used' by the calling HTML, then here are 5 attempts so far (they start !read) as well as the getC call that works.
use, intrinsic :: iso_fortran_env, only: input_unit, output_unit use, non_intrinsic :: IFPORT ... nin = input_unit ... if(IsLike(value,'POST')) then !How much content is waiting call GET_ENVIRONMENT_VARIABLE('CONTENT_LENGTH', value, length, status) ... read(value, *, iostat=my_iostat, iomsg=my_iomsg) ilen ... !Try reading straight from stdin (none work) !read (nin, '(a)', iostat=my_iostat, iomsg=my_iomsg) value(1:ilen-1) !read (nin, *, iostat=my_iostat, iomsg=my_iomsg) value(1:ilen) !read (nin, *, iostat=my_iostat, iomsg=my_iomsg) value !Try one character at a time do i = 1, ilen my_iostat = getC(value(i:i)) ! WORKS! but requires USE IFPORT !read (nin, '(a1)', advance='NO', iostat=my_iostat, iomsg=my_iomsg) value(i:i) !read (nin, '(a1)', iostat=my_iostat, iomsg=my_iomsg) value(i:i) ... end do write(nout,'(a)') 'Formatted read found value = "'//trim(value)//'"<br><br>'
I have a working solution, as shown above. It is just that I do not understand why!
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Fortran formatted READ is record-oriented, and wants a record with a line terminator. You should be able to get what you want if you open the file ACCESS='STREAM', FORM='UNFORMATTED' and read into a character variable (with an unformatted READ).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Steve,
Your suggestion works, many thanks.
What I have learnt is that I can use OPEN on a preconnected channel (stdin) and specify things like access='stream' and form='unformatted' as you suggest, this may be more widely useful than just this post on the forum.
BW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Glad to have helped.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page