- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear All,
I used a code posted here by Jugoslav as an example of using pipes on Windows, redirecting own I/O to pipe ends etc. Everything works fine. I was able to print to console (using unit 0) and to pipe (using *) within the same program. However, have another pretty complex software, which prints to console, calls other programs (execs), and reports progress by using Fortran carriage control (in order to overwrite previous lines). And also within this code I need to implement pipes for IPC with one of the exec. And here problems start. It seems that commands are not written to pipe correctly. What I'm doing wrong, or where can I learn on what to do to make this working (correctly). I have some (limited) experience with this on Linux but...
Is this issue with carriage control or I did something wrong in a different place??
As an additional info - other execs also use Fortran carriage control (to print it's own status in single line) except the "piped" exe (I guess).
this is portion of Jugoslav's example and below I simply try to write (*, *) command string.
I used a code posted here by Jugoslav as an example of using pipes on Windows, redirecting own I/O to pipe ends etc. Everything works fine. I was able to print to console (using unit 0) and to pipe (using *) within the same program. However, have another pretty complex software, which prints to console, calls other programs (execs), and reports progress by using Fortran carriage control (in order to overwrite previous lines). And also within this code I need to implement pipes for IPC with one of the exec. And here problems start. It seems that commands are not written to pipe correctly. What I'm doing wrong, or where can I learn on what to do to make this working (correctly). I have some (limited) experience with this on Linux but...
Is this issue with carriage control or I did something wrong in a different place??
As an additional info - other execs also use Fortran carriage control (to print it's own status in single line) except the "piped" exe (I guess).
this is portion of Jugoslav's example and below I simply try to write (*, *) command string.
---------------------------------------------------------------------A.
IF (CreateProcess(NULL, Path, NULL, NULL, TRUE, 0, NULL, NULL, SI, PI).EQ.FALSE) THEN
WRITE(*,*) "Cannot create child process. Error code = ", GetLastError()
STOP
END IF
!Redirect our own I/O to appropriate pipe ends
!NB: you have to SetStdHandle BEFORE you write(*) anything to it.
!In a gui app, these handles are normally not used anyway.
iret = SetStdHandle(STD_OUTPUT_HANDLE, hChildStdInWr)
iret = SetStdHandle(STD_INPUT_HANDLE, hChildStdoutRd)
---------------------------------
My statements follow here.
------------------------------------------------------------
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Um, I admit I've lost you... for the start, you refer to this kind of carriage control? If you do, I must say that a) it's Greek to me and b) I don't know how it would interact with pipe mechanism, but I can imagine that it would interact badly.
Note that you can "select" what you will read/write to the pipe and what to the screen with some code changes (i.e. without using SetStdHandle for your own output), for example (untested):
Note that you can "select" what you will read/write to the pipe and what to the screen with some code changes (i.e. without using SetStdHandle for your own output), for example (untested):
INTEGER, PARAMETER:: PIPE=42
INTEGER, EXTERNAL:: UOPEN
OPEN(PIPE, FILE="MyPipe", USEROPEN=UOPEN)
WRITE(PIPE, "(A)") "Foobar" !This goes to the pipe
WRITE(*, "(A)") "Foobar" !This goes to the screen
...
!=======
INTEGER FUNCTION UOPEN( FILENAME, DESIRED_ACCESS, SHARE_MODE, &
A_NULL, CREATE_DISP, FLAGS_ATTR, B_NULL, UNIT, FLEN )
!Declare all args as integer -- shouldn't matter as you don't use them.
!hChildStdInWr should be global, or CreatePipe here:
UOPEN = hChildStdInWr
END FUNCTION UOPENIn the code, just change WRITE(*) to WRITE(PIPE) where appropriate, i.e. skipping the progress messages and like.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Jugoslav,
many thanks for your, as always invaluable, advice. I wanted to do exactly that, I mean, separate read/write to pipe and to console (in the presence of Fortran carriage control setting). Sorry for not being clear enough about that from the very beginning. I have no idea what's wrong with Fortran carriage control (I had in mind that what you mentioned, where + outputs the record (at the current position in the current line) and a carriage returns), and where it messes up with pipe.
I've just used your suggestion in a test code by simply replacing:
iret = SetStdHandle(STD_OUTPUT_HANDLE, hChildStdInWr)
iret = SetStdHandle(STD_INPUT_HANDLE, hChildStdoutRd)
with
OPEN(PIPE, FILE="MyPipe", USEROPEN=UOPEN)
It seems to work OK. Thanks a lot.
Please let me ask you two more things:
(1) how should I correctly clean up after using that (CloseHandle, close file?)
(2) I'm getting this warning (for all of 4 handles)
Warning: %LOC is being stripped from argument which has REFERENCE and IGNORE_LOC attributes. [HCHILDSTDINRD]
Should I do something about it or it's just the way it is.
Thanks once more for your help.
A.
many thanks for your, as always invaluable, advice. I wanted to do exactly that, I mean, separate read/write to pipe and to console (in the presence of Fortran carriage control setting). Sorry for not being clear enough about that from the very beginning. I have no idea what's wrong with Fortran carriage control (I had in mind that what you mentioned, where + outputs the record (at the current position in the current line) and a carriage returns), and where it messes up with pipe.
I've just used your suggestion in a test code by simply replacing:
iret = SetStdHandle(STD_OUTPUT_HANDLE, hChildStdInWr)
iret = SetStdHandle(STD_INPUT_HANDLE, hChildStdoutRd)
with
OPEN(PIPE, FILE="MyPipe", USEROPEN=UOPEN)
It seems to work OK. Thanks a lot.
Please let me ask you two more things:
(1) how should I correctly clean up after using that (CloseHandle, close file?)
(2) I'm getting this warning (for all of 4 handles)
Warning: %LOC is being stripped from argument which has REFERENCE and IGNORE_LOC attributes. [HCHILDSTDINRD]
Should I do something about it or it's just the way it is.
Thanks once more for your help.
A.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ArturGuzik:
(1) how should I correctly clean up after using that (CloseHandle, close file?)
I'm fairly sure that normal Fortran CLOSE(PIPE) calls (among other things) CloseHandle, so you probably don't have to do anything. I'm not sure if CloseHandle for the opposite end is required, but it probably won't do harm.
ArturGuzik:
(2) I'm getting this warning (for all of 4 handles)
Warning: %LOC is being stripped from argument which has REFERENCE and IGNORE_LOC attributes. [HCHILDSTDINRD]
Should I do something about it or it's just the way it is.
That sounds as if you have used LOC() or %LOC() around the argument where it wasn't necessary (i.e. the argument is already declared as REFERENCE in the function's INTERFACE block). The warning is harmless in itself.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jugoslav,
thank you again for educating me.
The only place where LOC is used (i was playing with your example code) is:
iret = CreatePipe(LOC(hChildStdinRd), LOC(hChildStdinWr), SA, 0)
iret = CreatePipe(LOC(hChildStdoutRd), LOC(hChildStdoutWr), SA, 0)
so understand that LOC is not required here.
thanks once more.
A.
PS. When trying to reply (and write text) I'm getting "irresponsive JavaScript" warning message in my FireFox, which also becomes ... irresponsive. Is that normal or my setting/FireFox is incorrect/wrong?
(while editing message, what I'm doing right now, is without any problem).
thank you again for educating me.
The only place where LOC is used (i was playing with your example code) is:
iret = CreatePipe(LOC(hChildStdinRd), LOC(hChildStdinWr), SA, 0)
iret = CreatePipe(LOC(hChildStdoutRd), LOC(hChildStdoutWr), SA, 0)
so understand that LOC is not required here.
thanks once more.
A.
PS. When trying to reply (and write text) I'm getting "irresponsive JavaScript" warning message in my FireFox, which also becomes ... irresponsive. Is that normal or my setting/FireFox is incorrect/wrong?
(while editing message, what I'm doing right now, is without any problem).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Artur,
The forum problem with the Firefox browser is known. I'm told it's being worked on, but it has been a long time. I recommend using the IE Tab extension and tell it to load this forum using IE.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page