Home / Microsoft / Microsoft DOS / Batch file to run a program
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] - (Bottom) Print
Author Topic: Batch file to run a program  (Read 561 times)
Zahra
Topic Starter
Newbie



Posts: 2


« 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
IP logged
Geek-9pm
Sage



Thanked: 327
Posts: 8,047

Computer: Specs
Experience: Familiar
OS: Windows XP


Geek After Dark

« 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?
IP logged
Zahra
Topic Starter
Newbie



Posts: 2


« Reply #2 on: November 12, 2009, 09:01:33 PM »

I am running a code written in quick basic.
IP logged
billrich
Guest
« 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 » IP logged
gh0std0g74
Apprentice



Thanked: 37
Posts: 590


« 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?
IP logged

Geek-9pm
Sage



Thanked: 327
Posts: 8,047

Computer: Specs
Experience: Familiar
OS: Windows XP


Geek After Dark

« 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.




IP logged
Pages: [1] - (Top) Print 
Home / Microsoft / Microsoft DOS / Batch file to run a program « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.083 seconds with 20 queries.