1.

Solve : Batch file to run a program?

Answer»

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
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?I am running a code written in quick basic. 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/



@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?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.






Discussion

No Comment Found