- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Use ShellExecuteEx and you get the process ID returned in the ShellExecuteInfo structure you have to use.

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