- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
I have a need to run a 3rd party program inside Fortran (CVF) which I've been able to do using SYSTEM, SYSTEMQQ and RUNQQ. However the 3rd party program writes a lot of console messages which I'd like to both suppress from the user's view, and also to capture so I can scan it programmatically for key messages in my CVF app running on Windows XP.
Is there a simple way of doing this in CVF? I see references to CreateProcess() and haven't tried it yet, but reading the CVF helps on the other commands didn't seem to show any special mechanism/options for output control. When the program is run manually from the commandline, I can redirect the output to a file(s), and it shows that the program is making use of both stdout and stderr ... so I need some way to control these outputs when running inside a CVF app.
Any suggestions, sample code, or doc links appreciated. Thanks.
- Longden
Is there a simple way of doing this in CVF? I see references to CreateProcess() and haven't tried it yet, but reading the CVF helps on the other commands didn't seem to show any special mechanism/options for output control. When the program is run manually from the commandline, I can redirect the output to a file(s), and it shows that the program is making use of both stdout and stderr ... so I need some way to control these outputs when running inside a CVF app.
Any suggestions, sample code, or doc links appreciated. Thanks.
- Longden
링크가 복사됨
6 응답
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Well, CreateProcess will certainly do it - you can specify a handle of your choice for standard output. Or you could do it as simply as:
i = SYSTEM('dir > dir.txt')
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
How embarrassing.
Maybe I should ask a more challenging question like "what's your favorite color" :)
Thx.
BTW, is there any advantage to using SYSTEM vs SYSTEMQQ vs RUNQQ?
Maybe I should ask a more challenging question like "what's your favorite color" :)
Thx.
BTW, is there any advantage to using SYSTEM vs SYSTEMQQ vs RUNQQ?
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Well, don't be hard on yourself - some of these routines don't execute in a shell so can't do redirection. I think RUNQQ is one of them. SYSTEMQQ is pretty much the same as SYSTEM, I think. There may be differences as to whether any wait for completion or not. Then there's my favorite, ShellExecute, a Win32 API routine, perfect for opening documents or running programs without a command window opening.
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
The Fortran Help mentions using Win API CreateProcess(). Is there a reason for your preference of ShellExecute() over CreateProcess()?
Also, there is a possibility that the command being executed may lock or otherwise take a long time, in which case it'd be nice to be able to monitor the execution time from the calling CVF code and cancel the shell (or thread?) if it exceeds a specific time without returning control (ie, ending). Are any of the candidate functions/WinAPIs better suited for something like this?
Also, there is a possibility that the command being executed may lock or otherwise take a long time, in which case it'd be nice to be able to monitor the execution time from the calling CVF code and cancel the shell (or thread?) if it exceeds a specific time without returning control (ie, ending). Are any of the candidate functions/WinAPIs better suited for something like this?
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
ShellExecute is for when you just want to start a program in the background and keep going. It's especially handy for opening documents such as web pages as you don't have to specify a program to open the document. It's much easier to use than CreateProcess and does not create a console window the way that RUNQQ and friends do. But once the process is created, you have no control over it and can't even identify it.
If you want to monitor the process you would most likely want to use CreateProcess to get the process handle.
If you want to monitor the process you would most likely want to use CreateProcess to get the process handle.
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Use ShellExecuteEx and you get the process ID returned in the ShellExecuteInfo structure you have to use.
