- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, for the "SYSTEM" intrinsic only return the exit code of a shell command but not the output from it, so is there any approach to get the output within fortran code ? Such as, the current date string returned by shell command "%DATE%" ? I have tried to echo the date string to txt file and then read it, but it's really bothered, are there any simpler ways ?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Well if I just wanted the date there is a standard Fortran intrinsic you can call: DATE_AND_TIME
But in answer to you question it can be done but there isn't a "simple" way. Getting data via text files is one way. Creating or attaching to an existing console window is also possible and reading then reading from its text buffer is another way. The latter requires understanding programming with the windows API.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you show me an example of the way of attarching and then reading from the text buffer of an existing console ? Thanks a lot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Reading the text from a console window is non-trivial. At least until you do it once (your way), then reuse the subroutine you wrote. This is additionally problematic when you do not want the console window to hang around. Redirecting "terminal" output to file is much better. And once you have written his subroutine, you can reuse it later.
For standard types of functions you have the Fortran standard functions as well as the Windows functions (on Windows machines), or equivalent Linux functions on those machines. You can also the C interoperability capability to call C/C++ functions (your own or from various libraries).
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Blane J. wrote:
Can you show me an example of the way of attarching and then reading from the text buffer of an existing console ? Thanks a lot.
Use Google, enter "console functions windows", no quotes.
One of the first links will be: https://msdn.microsoft.com/en-us/library/windows/desktop/ms682073(v=vs.85).aspx
The function you might want is ReadConsoleOutputCharacter.
However, this also requires you to learn how to get the Windows handle to the console (of interest) screen buffer.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The simpler way would be to execute a command with a redirect to a file and then read the file. We've supported the standard EXECUTE_COMMAND_LINE for a while now.
What do you really want to do?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Note, #5 will get you access to the information sitting in the console window and not what may have scrolled off the bottom of the window. (this is what you asked for).
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for your suggestion, Jim and Steve.
And by the way, DATE_AND_TIME intrinsic only returns time info, I don't aware of any intrinsic can do time calculation. So what I really want to do is to call Linux shell command "date" to do some time calculation within fortran code, and then get the output time string and use it after. It seems that the most simple way is to redirect output to file and then read it which I am already in use.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
https://software.intel.com/en-us/node/580486#880ABC94-8A0B-4045-B07D-D8E9A6EC007E
No it can return date and time like the name says
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Blane wants to do date calculations, which indeed there is no Fortran intrinsic for. Given that this is the Windows forum, I would have recommended Windows API routines for doing conversion to and from various date formats, but Blane mentions Linux so I don't know if there's an accessible routine to do that sort of thing. There's probably something in a C library...
That said, Fortran programmers have been doing date calculations for decades - it's not terribly difficult and I am sure there are examples all over the net.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The is a comprehensive and free set of Fortran date time tools at https://github.com/milancurcic/datetime-fortran ....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you both. I see, so I think the better way is to do the calculation (what ever shell command could do) using user defined subroutine when there's no accessble intrinsic doing the same thing just like "datetime" above. By the way, would fortran plan to have the sort of intrinsic funtion which can retrive output from shell command in the future ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Not in standard Fortran. It did add EXECUTE_COMMAND_LINE in Fortran 2008, which we support, but capturing the output is not included. (I don't know of similar routines in C that would capture the output.) Redirecting the command output to a file or named pipe and reading it is quite common.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A good source of calendar functions in Fortran is John Burkardt's calpak library. Look at URL:
http://people.sc.fsu.edu/~jburkardt/f_src/calpak/calpak.html

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page