Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch file to run a program  (Read 2589 times)

0 Members and 1 Guest are viewing this topic.

Zahra

    Topic Starter


    Newbie

    Batch file to run a program
    « on: November 12, 2009, 03:05:01 PM »
    Hi
    I am trying to use a batch file for inputting variables into a program and it works for the variables which are input before running the code, but not after. Here's how I approach it:
    1- make a batch file containing this line:
    code.exe < input.txt
    2- enter variables in the input.txt, e.g:
    yes
    2
    input.in
    1

    output.out
    3- run the batch file. It reads the input variables and runs the code, but after finishing the code, doesn't write the results into output.out

    Any idea?
    Thanks

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Batch file to run a program
    « Reply #1 on: November 12, 2009, 05:03:27 PM »
    It can make a difference knowing which program you are using.
    The DOS redirection option expects  the a program use the standard input/output. I believe in  C it is in the directive conio.h ...
    or something like that.

    A program written for Windows may use another method of getting keyboard input. Also, some programs purge the keyboard input until an appropriate time. Don't ask them why they do this, but they do.
    A viable alternative is to use some type of macro key program that will emulate the actual keystrokes you would use with a program. This will guarantee that the keystrokes go through the Windows operating system the way the application expects it to. Does this make any sense?

    Zahra

      Topic Starter


      Newbie

      Re: Batch file to run a program
      « Reply #2 on: November 12, 2009, 09:01:33 PM »
      I am running a code written in quick basic.

      billrich

      • Guest
      Re: Batch file to run a program
      « Reply #3 on: November 13, 2009, 07:27:34 PM »
      C:\>type input.txt  |   code.exe  >  output.txt

      or

      C:\>code.exe < input.txt   >  output.txt

      Rem  tryit.bat
      Code: [Select]
      @echo off

      type input.txt  |   code.exe  >  output.txt

      rem  or

      code.exe < input.txt   >  output.txt

      http://support.microsoft.com/kb/q110930/



      « Last Edit: November 13, 2009, 07:54:53 PM by billrich »

      gh0std0g74



        Apprentice

        Thanked: 37
        Re: Batch file to run a program
        « Reply #4 on: November 13, 2009, 07:59:10 PM »
        @OP it depends on how your quick basic program is written. Is it programmed to accept standard input and input redirection? If it does not, then of course you won't be able to use "|" pipes, or "<" .. logical?

        Geek-9pm


          Mastermind
        • Geek After Dark
        • Thanked: 1026
          • Gekk9pm bnlog
        • Certifications: List
        • Computer: Specs
        • Experience: Expert
        • OS: Windows 10
        Re: Batch file to run a program
        « Reply #5 on: November 13, 2009, 09:18:18 PM »
        Hello again.
        Well, I see you are using QBasic.nothing wrong with that, in fact it is easy way to solve some problems is otherwise quite difficult using just the DOS commands.
        Here's an example that might be of some help to you.
        Let's say I write a very simple program in QBasic that looks like this:
        Quote
        Microsoft Windows XP [Version 5.1.2600]
        d:\bin>type test.bas
        PRINT " this is a test"
        INPUT a$
        PRINT a$
        SYSTEM
        As you can see here I have named it "test.BAS".
        Now I can run the program using the following command line option:
        Quote
        d:\bin>qbasic /run test
        The output will be like this:
        Quote
        this is
        ? HELLO
        HELLO

        d:\bin>
        Of course, I had to enter the text "HELLO" and the program at code my response. Now, using the editor I will make a small program that I just call "inpu" and save it. The content is as follows:
        Quote
        d:\bin>type inpu
        thisis inpu

        d:\bin>
        Now I am ready to test the redirection feature of the, actually the command line in Windows XP, as follows:
        Quote
        d:\bin>qbasic /run test <inpu
         this is a test
        ? thisis inpu
        thisis inpu

        d:\bin>
        Works like a happy puppy!

        Hope this is of some help to you.
        Please note this is QBasic, not the compiler.