Silverfrost Forums

Welcome to our forums

Redirection of Standard in and standard out

6 Feb 2008 11:24 #2742

Hi,

I am calling a DOS executable from a windows application (winapp). Each time the program is called a DOS window appears. I would like to avoid the appearance of the DOS window.

From a google search the solution seems like a redirection of the standard input and output. However I do not know where to start to achieve this in Fortran 😦

My code has the following form:

winapp

program dosbox
  integer :: ifail

  ! Call the dos executable
  ! 
  ! ??? Redirect STDIN and STDOUT ???
  !
  call cissue@('C:\\temp\\pol2poly.exe',ifail)

end program

How could I avoid the appearance of the DOS window using the FTN95 compiler?

Jacques

6 Feb 2008 12:20 #2743

There are various simple things that you could try...

Try using the alternative routines START_PROCESS@ or START_PPROCESS@.

Another thing that may be relevant is the type of executable. If it is starting up in a DOS box then it must be a 'Console' application rather than a 'Windows' application. For example, the FTN95 WINAPP command is used to create a Windows applicatioin.

6 Feb 2008 1:31 (Edited: 13 Feb 2008 10:51) #2744

Hi Paul,

even with start_process@ the DOS window appears. Maybe an explanation of my program helps. I create a geometry for a FEM program in our internal file format. When meshing the geometry we use an external mesher. To to that we need to convert the file format to get the mesher to work. And since I only have the converter as an executable I want to call it as a 'subroutine' from the main program which is a FTN95 winapp.

A colleague of mine does something similar in C++. The code is below. He makes use of what he calles pipelines. If I convert from a command line the commands are as follows:

pol2poly file1.pol converted.poly triangle -pq30AnY converted.poly t2fpl converted.1.poly file1.fpl

Jacques

static BOOL RunConsolProcess(LPTSTR lpszCommand)
{
    STARTUPINFO         si = {0};
    PROCESS_INFORMATION pi;
    si.cb = sizeof(si);
    si.dwFlags = STARTF_USESHOWWINDOW; //...wShowWindow Flag von STARTUPINFO-Struktur freischalten und...
    si.wShowWindow = SW_HIDE;           //...Fenster (Konsole) nicht anzeigen!
    DWORD dwCreatitonFlags = CREATE_NEW_PROCESS_GROUP | IDLE_PRIORITY_CLASS;
    if (!CreateProcess(NULL, lpszCommand, NULL, NULL, TRUE, dwCreatitonFlags, NULL, NULL, &si, &pi))
	return FALSE;
    else
    {
      WaitForSingleObject(pi.hProcess, INFINITE);
	CloseHandle(pi.hProcess);
    }
    return TRUE;
}
6 Feb 2008 4:41 #2747

Another possibility is to try using the Windows API function WinExec with the parameter SW_HIDE (=0 I think). This will probably be declared in WINDOWS.INS etc.

6 Feb 2008 10:26 #2752

Jacques,

If it is any help, the 'pipe' to sent your STDOUT output to oblivion is >nul.

Give it a try. Open a DOS box. Type :

DIR /?
 

... you will see the directory help. It is too long for one 25 line screen, so it will pause, waiting for you to type <ret> to get the second screen

Now type

DIR /P >nul

... you will not see the first screenful, as it has gone to 'nul'. However, you don't know you have to type a <ret> to (not) get the second screen!

Make a file with a single <ret> in it, using the DOS command

COPY    CON     RETFILE
<ret><CTRL-Z>

Now try

DIR /? <RETFILE    >NUL

The output goes to nul, the <ret> is supplied to cause the second screen to be sent there also.

If you put a different device instead of NUL like LPT1:, or a file, the output would get sent there. If you used a double pipe >> then the stuff gets appended. If you use this pipe | then you can send the output of the first program to be input to a second. If you have redirected STDOUT to NUL, you won't see a DOS box open to display it!

Windows still has lots of DOS stuff in it - just like FTN95!

I hope this is the answer you need. It isn't FTN95 ...

Regards

Eddie

13 Feb 2008 11:30 #2781

Hi Eddie,

thanks for the reply. However, I did not exactly understood what you ment. I am familiar with the redirection using >. Even using that, I still get a dos window that appear very quick.

But I think that this could help to explain my problem better. If I would like to get the files in a directory using the dos dir function from within my program it coul like something like:

winapp

program dosbox
  integer :: ifail

  call cissue@('dir c:\\temp >c:\\temp\\screen.txt',ifail)

end program

Executing this program results in a file named screen.txt in the c:\temp directory. The content of the directory is not displayed on the screen. However, the dos window stille appear.

If the above program can execute without a dos box appearing, then my problem will be solved!

Jacques

13 Feb 2008 12:24 #2785

You can use the routine called FILES@ to get a list of files directly.

13 Feb 2008 3:59 #2787

Hi Paul,

the program only illustrates the appearance of the DOS window.

My question

How can I change the above program to [u:3d9876a656]avoid[/u:3d9876a656] the DOS window?

Jacques

13 Feb 2008 7:11 #2788
winapp 
program dosbox
  include <windows.ins>
  integer :: i 
  i = WinExec('dir c:\\temp >c:\\temp\\screen.txt',0)
end program 
13 Feb 2008 9:20 #2789

Jacques,

I misunderstood. Seems like every DOS app pops up a DOS window to run in.

Redirection means you don't have to have anything visible in that window!

To have no window, it has to be a Winapp, run minimised, and with no taskbar icon! POL2POLY would probably compile into that with a handful of extra commands in a few seconds - if only you had the source code.

Who wrote it?

Eddie

14 Feb 2008 3:14 #2792

Hi Paul and Eddie,

the code below work just as I would like it to! Of coarse, the code for pol2poly is available, but we have other programs for which we are only the customer. And the problem is that the programmer is not familiar with WinAPI functions! He is still an 'old' Fortran programmer.

Our GUI's is only a front-end for the program.

The thing with the redirection definition seems to be different for different people. When I first started to solve the problem the keywords to do a google search was unknown and after a while it seemed like redirection of the output is the keyword to use.

It would be interessting to know wheter there exists a formal definietion for redirection and the how to avoid a DOS window appearing.

Thanks for the help! The forum is great stuff :lol:

Jacques

winapp 
program dosapp 
  include <windows.ins> 
  integer :: i
  ! Call the dos executable without apperance of a DOS window
  ! 
  i = WinExec('pol2poly.exe file1.pol file2.pol',0) 
end program
Please login to reply.