- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear IVF Forum,
I am using a function OSCALL.f90 (which is a wrapper for the windows API function CreateProcess) to start an exe (Rgui.exe - download from http://cran.r-project.org/), from a Fortran console application.
When the console program finishes, the window does not close easily.
If I click on the X on the topright corner of the console window, than the R gui window closes first and I have wait until windows closes the console window using "End Program"
Attached is source code file that reproduces this behaviour.
It is run on IVF11.1.035, VX2008 and Windows XP (Service Pack 3) 32 bit
Prior to approx September last year, this not a problem, and the Fortran console window stayed closed like normal and the R gui window stayed open afterwards.
This has also been tested with a Fortran Windows Application (not shown here) and this problem does not occur.
I am not that familar with the arguments to CreateProcess, is there something that needs to be changed to change this behavoir.
I did also consider using SYSTEMQQ to open the Rgui.exe, but SYSTEMQQ seems to wait until the exe finishes, whereas I want to run the fortran console window and Rgui exe in paralell.
Mark
Link Copied
9 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - mark.thyernewcastle.edu.au
Dear IVF Forum,
I am using a function OSCALL.f90 (which is a wrapper for the windows API function CreateProcess) to start an exe (Rgui.exe - download from http://cran.r-project.org/), from a Fortran console application.
When the console program finishes, the window does not close easily.
If I click on the X on the topright corner of the console window, than the R gui window closes first and I have wait until windows closes the console window using "End Program"
Attached is source code file that reproduces this behaviour.
It is run on IVF11.1.035, VX2008 and Windows XP (Service Pack 3) 32 bit
Prior to approx September last year, this not a problem, and the Fortran console window stayed closed like normal and the R gui window stayed open afterwards.
This has also been tested with a Fortran Windows Application (not shown here) and this problem does not occur.
I am not that familar with the arguments to CreateProcess, is there something that needs to be changed to change this behavoir.
I did also consider using SYSTEMQQ to open the Rgui.exe, but SYSTEMQQ seems to wait until the exe finishes, whereas I want to run the fortran console window and Rgui exe in paralell.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I haven't looked at your code, but have you considered using ShellExecute instead of CreateProcess?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Steve Lionel (Intel)
I haven't looked at your code, but have you considered using ShellExecute instead of CreateProcess?
No, I haven't . Could you please provide a short example where ShellExecute is used to open another exe, so I can try it out?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Steve Lionel (Intel)
Here's an example of using ShellExecute. Just feed it the path to your EXE and use the Open action.
Steve,
I tried using ShellExecute and the same problem occurs (i.e. trouble closing Fortran console window) if I ask if user input from the console, via either read(*,*) or pause. If I don't ask for any user input , it works ok (console flashes up and closes)
As I often use these commands to to enable users to view program output to the console before it closes this is a major limitation.
Cheers,
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your prompt response Steve, but I dont think the anykey.f90 example is what I am after.
I'll try to clarify what I would like to do
1. Run a fortran console exe (proga.exe) created using IVF11.1.035
2. Have proga.exe start another executable, called Rgui.exe (using CreateProcess/shellExecute or whatever)
3. After starting rgui.exe, proga.exe continues to run (i.e. does not wait for rgui.exe to finished and hence both exe's are running in parallel)
4. Enable proga.exe to accept some user input via pause or read(*,*)
5. proga.exe then finishes and the console window is closed
6. After proga.exe is a closed, the windows for Rgui.exe remains open.
Currently, using both createprocess and shellexecute what is happening is that when proga.exe finishes its console window stays open, until it is closed manually (by clicking on topright corner) and when its closed manually, the window for Rgui.exe also gets closed.
However, using Shellexecute, if a remove Step 4 (i.e. there is no user input), then all the following steps happen as I would like.
Is it possible to achieve the above using createprocess or shellexecute?
Here is the current way I am using CreateProcess
[plain] use dfwin, only: T_STARTUPINFO,T_PROCESS_INFORMATION,NULL,STARTF_USESHOWWINDOW,SW_HIDE,NULL_CHARACTER,NULL_SECURITY_ATTRIBUTES,CREATEPROCESS,WAITFORSINGLEOBJECT implicit none character(*), intent(in) :: Command !Command portion of the command line (i.e. the program name) character(*), intent(in) :: Args !Argument portion of the command line character(256) :: CmdLine !Work area for the command line integer, intent(in) :: iWaitMS !Process completion wait value in milliseconds integer, intent(out) :: iRet !Main return code integer :: iCRC !Return code for CreateProcess type (T_StartupInfo) :: StartInfo !CreatProcess parms type (T_Process_Information) :: ProcInfo !CreatProcess parms (created process info) ! ! Initialize return code ! iRet = 0 ! ! Insure console window is suppressed ! StartInfo%cb = 68 StartInfo%lpReserved = 0 StartInfo%lpDesktop = NULL StartInfo%lpTitle = NULL StartInfo%dwX = 0 StartInfo%dwY = 0 StartInfo%dwXSize = 0 StartInfo%dwYSize = 0 StartInfo%dwXCountChars = 0 StartInfo%dwYCountChars = 0 StartInfo%dwFillAttribute = 0 StartInfo%dwFlags = StartF_UseShowWindow StartInfo%wShowWindow = SW_HIDE StartInfo%cbReserved2 = 0 StartInfo%lpReserved2 = NULL ! ! Prepare the command line string and arguments ! cmdLine = '"' // trim(command) // '" ' // trim(args) // char(0) ! ! Initiate process ! iCRC = CreateProcess(null_character, & cmdLine, & null_Security_Attributes, & null_Security_Attributes, & .false., & Null, & Null, & Null_Character, & StartInfo, & ProcInfo) ![/plain]
Cheers,
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Perhaps some other Win32 experts would like to chime in here, but I would think that ShellExecute should do exactly what you want. I don't understand why proga is forcing you to close it when it finishes - at least when using ShellExecute. I might understand that with CreateProcess because, by default, you create a child process that is dependent on the parent.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Steve Lionel (Intel)
Perhaps some other Win32 experts would like to chime in here, but I would think that ShellExecute should do exactly what you want. I don't understand why proga is forcing you to close it when it finishes - at least when using ShellExecute. I might understand that with CreateProcess because, by default, you create a child process that is dependent on the parent.
Steve,
Considering what you have said I have done some more extensive testing and the problem seems to be specific to lauching the recent versions of Rgui.exe. When I launch other executables (e.g. Tinn-R.exe or textpad.exe) this problem does not occur. Also when I launch Rgui.exe for v2.6.2 or earlier it does not occur.
It only occurs if I launch Rgui.exe for versions >=2.7.0. I have sent a message to R-developers mailing list to find out what changed from v2.6.2 to v2.7.0. If I get an answer I will post it to this forum also.
Thank you very much for your time.
Mark

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