Re: Execute a batch file and wait for it to complete



On Mar 12, 8:50 pm, atmkoh <atm...@xxxxxxxxxxx> wrote:
I apologise if this topic has cropped up before. I am using
Silverfrost Fortran 95. I am trying to do a shell and wait but without
the hassle of win32 api etc. Is this possible ?

I have to dos batch files that execute proprietary programs.
(Temp1.bat and Temp2.bat)

The idea of putting "look at the first result" and "look at the second
result" is to see if the program will wait for it to finish before
printing and yes it does.

The problem I have is that the first system command spawns a new ms
dos console window which will not close when the program is compelted!
and until I manually close the console.

Is there a library that I can use to actually call the win32 api
direcltly ?

PROGRAM TEST
CALL SYSTEM('START/W C:\Projects\TEMP1.BAT')
PRINT *,' Look at the first result.'
CALL SYSTEM('START/W C:\Projects\TEMP2.BAT')
PRINT *,' Look at the second result.'
END PROGRAM TEST

1. I can't speak for the behavior of SYSTEM using Silverfrost. It
might interact differently from some other CALL SYSTEM() or i=SYSTEM()
or SYSTEMQQ... or RUNQQ... None of these are standard Fortran.

2. START/W appears to be doing what it is documented to do.

Here is part of the help screen generated on Vista (32) when invoked
by START /?

Starts a separate window to run a specified program or command.

START ["title"] [/D path] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
[/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /
BELOWNORMAL]
[/AFFINITY <hex affinity>] [/WAIT] [/B] [command/program]
[parameters]

..........
WAIT Start application and wait for it to terminate
command/program
If it is an internal cmd command or a batch file then
the command processor is run with the /K switch to
cmd.exe.
This means that the window will remain after the
command
has been run.

If it is not an internal cmd command or batch file
then
it is a program and will run as either a windowed
application
or a console application.
.........

So if you are invoking your program via a batch file with START /W,
which is the same as /WAIT,
the window will stay open, as described above.

3. There are a number of other ways to invoke your program.

Try something like

CALL SYSTEM('C:\Projects\TEMP1.BAT')
PRINT *,'first'
CALL SYSTEM('C:\Projects\TEMP2.BAT')
PRINT *,'second'
END

It depends on what TEMP1.BAT and TEMP2.BAT do, but on my system, when
compiled with g95, the following program

i=system('temp1.bat')
print *,'first done'
read *
i=system('temp2.bat')
print *,'second done'
read *
end

sends all console output to a common screen which closes after the
program ends.

temp1 invokes q1, temp2 invokes q2, q1 prints '1', q2 prints '2'.

If I remember correctly, START was not present in Win95 or Win98, but
was introduced with 2000 or XP.
So it is much more common to either put the name of the .bat file or
the name of the .exe file in the string passed to system rather than
using START. The main reason to use START is to do something unusual.

You used START, and it bit you.

--- e



.



Relevant Pages

  • Re: batch question
    ... window at great speed, without being executed. ... all I want is for the command to work inside a command prompt window. ... Your original batch file had two lines. ... you fell into a well-known trap: you are not executing ping.exe ...
    (microsoft.public.windowsxp.general)
  • Re: Batch File Problem - Batch File Enclosed
    ... I have added a batch file to my Startup folder to execute whenever ... The batch file works ok but it leaves a blank command ... I would like close this window using the batch file ...
    (microsoft.public.windowsxp.general)
  • Build instructions for loadcepc.exe
    ... Build instructions for loadcepc.exe ... a standard cmd.exe window. ... Execute the batch file setupenv.bat: ... command promt ...
    (microsoft.public.windowsce.platbuilder)
  • Build instructions for loadcepc.exe
    ... Build instructions for loadcepc.exe ... a standard cmd.exe window. ... Execute the batch file setupenv.bat: ... command promt ...
    (microsoft.public.windowsce.embedded)
  • Re: Batch File Problem - Batch File Enclosed
    ... I have added a batch file to my Startup folder to execute whenever ... The batch file works ok but it leaves a blank command ... I would like close this window using the batch file ...
    (microsoft.public.windowsxp.general)

Loading