Like Tree1Likes
  • 1 Post By rcgldr

Batch Files Help!

This is a discussion on Batch Files Help! within the Windows Programming forums, part of the Platform Specific Boards category; Hello guys, In my code i call a batch file which runs an external program. The batch file open the ...

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    20

    Batch Files Help!

    Hello guys,

    In my code i call a batch file which runs an external program. The batch file open the program successfully but what i want is to close the program after a certain amount of time the code i use is the one below but unfortunately it runs only through line 2 where it open the program then the commands after this line are not executed...!!

    Can you please check it out and tell me what am i doing wrong..?

    Code:
    @echo on
    xfoil.exe < airfoil.txt > xfoil.out
    
    
    ping 127.0.0.1 -n 13 >nul
    
    
    Taskkill /F /IM:cmd.exe

  2. #2
    Registered User
    Join Date
    Apr 2013
    Posts
    1,315
    You can use the batch file call command to spawn another batch file or program:

    Code:
    @echo on
    call xfoil.exe <airfoil.txt >xfoil.out
    @echo both batch file and xfoil are now running
    @ping 127.0.0.1 -n 13 >nul 
      
    @taskkill /f /im:xfoil.exe
    Last edited by rcgldr; 04-17-2013 at 07:27 PM.

  3. #3
    Registered User
    Join Date
    Mar 2013
    Posts
    20
    rcgldr thank you for your suggestion..! Unfortunately as i can understand the commands are executed till line 2 where we call xfoil. Then i don't know why but it doesn't proceed to the ping command nor the taskkill.

    I made a seperate batch file containing only the taskkill command and it works when it is executed it closes xfoil.exe but when i have it with the ping command it doesn't work..!!

  4. #4
    Registered User
    Join Date
    Apr 2013
    Posts
    1,315
    Sorry my mistake, what you want is "start" not call. You can enter "help start" at the command line to get the options.

    Code:
    @start xfoil.exe <airfoil.txt >xfoil.out
    @echo both batch file and xfoil are now running
    @rem delay for 12 seconds (-n param is 1 + # seconds to delay)
    @ping 127.0.0.1 -n 13 >nul
    @taskkill /f /im:xfoil.exe
    
    To compensate for my mistake, how to do a loop. doloop.bat calls loop.bat with an incrementing parameter 30 times). You can replace the 30 with %1 so that the number of loops is specified by the user.

    doloop.bat:
    Code:
    for /l %%c in (1 1 30) do @call loop.bat %%c
    loop.bat
    Code:
    @echo pass %1
    
    Another tidbit, if you're on a network and want to run batchfiles remotely on another machine, you can rename a file to use as a handshake between the two machines, using the batch command "if not exist name...". The "server" system runs a batch file with a loop and a delay (ping 127.0.0.1 -n 2 >nul). I usually bump the suffix for the handshake:

    server system:
    Code:
    @loop0:
    @ping 127.0.0.1 -n 2 >nul
    @if not exist flagfile.1 @goto loop0
    @rem let client system know server system is running
    @ren flagfile.1 flagfile.2
    @rem run some process
    @rem let client system know server system has completed
    @ren flagfile.2 flagfile.0
    @goto loop0
    client system
    Code:
    @if not exist flagfile.1 @ren flagfile.? flagfile.1
    @echo waiting for server to start
    @loop0:
    @ping 127.0.0.1 -n 2 >nul
    @if not exist flagfile.2 @goto loop0
    @echo waiting for server to complete
    @loop1:
    @ping 127.0.0.1 -n 2 >nul
    @if not exist flagfile.0 @goto loop1
    @echo server completed
    
    Last edited by rcgldr; 04-19-2013 at 02:50 AM.

  5. #5
    Registered User
    Join Date
    Mar 2013
    Posts
    20
    rcglr Thank you a lot for your help..!

    The problem i have with the start command is that i want to start in batch mode. So that i want to feed the file airfoil.txt to the xfoil so that it reads the commands that had to be executed from the txt file. With the call command this is easy to do i just write

    Code:
    call xfoil.exe<airfoil.txt>xfoil.out
    but with the start command the file is not feeded to the xfoil just the program starts normally without executing the commands on the .txt file.

    Do you know how can i fix that..?

    Thank you again

  6. #6
    Registered User
    Join Date
    Apr 2013
    Posts
    1,315
    try using quotes:

    start "xfoil.exe <airfoil.txt >xfoil.out"

    if that doesn't work, create another batch file called runxfoil.bat that has the command parameters and use

    start runxfoil.bat
    laserlight likes this.

  7. #7
    Registered User
    Join Date
    Mar 2013
    Posts
    20
    Quote Originally Posted by rcgldr View Post
    try using quotes:

    start "xfoil.exe <airfoil.txt >xfoil.out"

    if that doesn't work, create another batch file called runxfoil.bat that has the command parameters and use

    start runxfoil.bat
    Thank you that worked...!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. batch files
    By Sm33zy in forum Tech Board
    Replies: 5
    Last Post: 11-21-2008, 09:19 PM
  2. Batch Files
    By SirCrono6 in forum Tech Board
    Replies: 6
    Last Post: 03-13-2004, 09:44 AM
  3. batch files
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-28-2001, 12:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21