forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Redirection of Standard in and standard out

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+
View previous topic :: View next topic  
Author Message
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: Nürnberg, Germany

PostPosted: Wed Feb 06, 2008 12:24 pm    Post subject: Redirection of Standard in and standard out Reply with quote

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 Sad

My code has the following form:
Code:

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
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Wed Feb 06, 2008 1:20 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message AIM Address
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: Nürnberg, Germany

PostPosted: Wed Feb 06, 2008 2:31 pm    Post subject: Reply with quote

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

Code:

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;
}


Last edited by jjgermis on Wed Feb 13, 2008 11:51 am; edited 1 time in total
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Wed Feb 06, 2008 5:41 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message AIM Address
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Wed Feb 06, 2008 11:26 pm    Post subject: Reply with quote

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 :

Code:
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

Code:
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

Code:
COPY    CON     RETFILE
<ret><CTRL-Z>

Now try

Code:
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
Back to top
View user's profile Send private message
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: Nürnberg, Germany

PostPosted: Wed Feb 13, 2008 12:30 pm    Post subject: Reply with quote

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:

Code:

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
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Wed Feb 13, 2008 1:24 pm    Post subject: Reply with quote

You can use the routine called FILES@ to get a list of files directly.
Back to top
View user's profile Send private message AIM Address
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: Nürnberg, Germany

PostPosted: Wed Feb 13, 2008 4:59 pm    Post subject: Reply with quote

Hi Paul,

the program only illustrates the appearance of the DOS window.

My question
How can I change the above program to avoid the DOS window?

Jacques
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Wed Feb 13, 2008 8:11 pm    Post subject: Reply with quote

Code:
winapp
program dosbox
  include <windows.ins>
  integer :: i
  i = WinExec('dir c:\temp >c:\temp\screen.txt',0)
end program
Back to top
View user's profile Send private message AIM Address
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Wed Feb 13, 2008 10:20 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: Nürnberg, Germany

PostPosted: Thu Feb 14, 2008 4:14 pm    Post subject: Reply with quote

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 Laughing

Jacques

Code:

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+ All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group