- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi everyone,
I have a fortran main program from which I want to run an executable (foil.exe) with an instructions file (inst.txt). I am actually using the SYSTEMQQ(foil.exe < inst.txt) command, which works well.
Now, since my foil.exe sometimes fails convergence and crashes, I would like to insert the possibility to kill the executable after a fixed time interval. I studied the example provided by Mr. Steve Lionel http://software.intel.com/en-us/forums/topic/275071#comment-1548443, but i have some difficulty as I try to make things work. First, i tried to create a process which just runs the executable foil.exe, and everything is right, in the sense that I am able to control the timeout, and kille the application by the WaitForSingleObject instruction.
Problems arise when i try to add the instruction file to the procedure. As i read from the forum, create process does not accept cmd instructions like '<', so I created a batch file 'script.bat' with the full command ' foil.exe < inst.txts', and I made CreateProcess to run the batch file. The application runs properly, and the instructions are read correctly but, in this case, I am not able to control/kill the process with WaitForSingleObject.
Am I doing something wrong? I have to point out that this is my first experience with CreateProcess instruction. I found this topic http://msdn.microsoft.com/en-us/library/windows/desktop/ms682499(v=vs.85).aspx which I suspect could be related to my problem, but the fact that it refers to C++ applications poses serious difficulties, as i know nothing, or so, about C++ programming.
Does anyone have any experience of similar situation?
Thank you for your time,
Luca
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Luca,
Try this: Insted of running a batch file, run CMD.EXE followed by an enquoted text argument that consists of the former SYSTEMQQ commant line. Prior to this text, you can optionally insert other options for CMD to use. From CMD window, type "help cmd" to get a list of options.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If the commanline for the new process is complex, enclose it in double-quotes, and be sure to null-terminate, eg,
progname = ' "c:\mydir\myprog < info.txt" 'c
[fortran]
TYPE(T_STARTUPINFO) :: si
TYPE(T_PROCESS_INFORMATION) :: pi
! TYPE T_PROCESS_INFORMATION
! SEQUENCE
! integer(HANDLE) hProcess ! knowns HANDLE
! integer(HANDLE) hThread ! knowns HANDLE
! integer(DWORD) dwProcessId ! knowns DWORD
! integer(DWORD) dwThreadId ! knowns DWORD
! END TYPE
CALL ZeroMemory (LOC(pi), SIZEOF(pi))
CALL ZeroMemory (LOC(si), SIZEOF(si))
si%cb = SIZEOF(si)
si%dwFlags = STARTF_USESHOWWINDOW
si%wShowWindow = SW_SHOWNORMAL
IF (CreateProcess (NULL, & ! process name
progname, & ! command line
NULL_SECURITY_ATTRIBUTES, & ! security attributes
NULL_SECURITY_ATTRIBUTES, & ! thread attributes
FALSE, & ! handle inheritance
0, & ! creation flags
NULL, & ! environment block
NULL, & ! initial working path
si, & ! startup info
pi) ) THEN ! process info
! child process is running...
rval = CloseHandle (pi%hProcess)
rval = CloseHandle (pi%hThread)
! problem creating new process
ELSE
rval = GetLastError()
SELECT CASE (rval)
CASE (ERROR_FILE_NOT_FOUND)
emsg = 'FILE NOT FOUND'C
CASE (ERROR_DIRECTORY)
emsg = 'DIRECTORY NOT FOUND'C
CASE (ERROR_PATH_NOT_FOUND)
emsg = 'PATH NOT FOUND'C
CASE (ERROR_BAD_PATHNAME)
emsg = 'BAD PATH NAME'C
CASE DEFAULT
emsg = 'Cannot create process'c
END SELECT
rval = MessageBox (ghwndMain, emsg, "Launch Error"C, &
IOR(MB_OK,MB_ICONERROR))
END IF
[/fortran]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Why are you using the nonstandard 'string'C syntax? Doesn't it create problems when there are backslashes in the string, as here?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much for your help. I will try following your suggestions.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page