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

Author Topic: Batch File Q: Please Help Me!  (Read 43873 times)

0 Members and 1 Guest are viewing this topic.

dosnovice

  • Guest
Batch File Q: Please Help Me!
« on: July 26, 2005, 12:24:24 PM »
This will probally seem like a stupid question to any experienced dos user, but I need to know if it is possible for a batch file to answer prompts in a program.  I want to create a batch file that will start a dos program (called rmovave) and answer the prompts so the program will run without me having to type in the same paramaters over and over.  The program, rmovave, will not accept an answer file or I'd fix it that way.  Maybe what I want to do isn't possible? It seems like it should be.  Please help me as I have several hundred files to run through this program (and three others after that!!).  Thanks.

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Batch File Q: Please Help Me!
« Reply #1 on: July 26, 2005, 12:56:44 PM »
If you are using XP or 2000 try:
Code: [Select]

set /p var=promptstring


If you are using DOS or Win9x there is a nifty little utility. Answer allows you to prompt for user data and store it in the environment space. Each time it runs the environment variable is overwritten, so be sure to save each value to your own variables. Put into a directory along your path and you can use it anywhere.

Hope this helps. 8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

dosnovice

  • Guest
Re: Batch File Q: Please Help Me!
« Reply #2 on: July 26, 2005, 01:16:28 PM »
Thanks for the help sidewinder.  I am using command prompt in windows xp.  You have to forgive me, I'm really new to using dos.  After I add your code should I put /p before each line of prompt?  Thanks again.

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Batch File Q: Please Help Me!
« Reply #3 on: July 26, 2005, 01:24:29 PM »
Yes. Something like this:

Code: [Select]

set /p input=Enter name of input file:
set /p output=Enter name of output file:


You can then use the %input% and %output% variable names in your batch file.

Good luck. 8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

dosnovice

  • Guest
Re: Batch File Q: Please Help Me!
« Reply #4 on: July 26, 2005, 01:40:10 PM »
I tried what you told me to do but the /p lines don't answer the prompts in my program (rmovave).  I think I'm in a bit over my head.  I just learned what a .bat file is today.  I guess I have to run all hundred plus files I have manually.  

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Batch File Q: Please Help Me!
« Reply #5 on: July 26, 2005, 02:16:12 PM »
My mistake, I misread your question. Some programs expect parameters on the command line. Some programs can read redirected input. Some programs will accept input thru the pipe and some programs can read an answer file. What program are you referring to?

:'(
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

dosnovice

  • Guest
Re: Batch File Q: Please Help Me!
« Reply #6 on: July 26, 2005, 02:26:11 PM »
The program is called Rectified Moving Average (rmovave for short).  I don't think it's very common.  I believe it's written in Pascal if this helps. I'm using it to smooth waveform files (people's heartbeats or ECGs) to isolate a certain part of the wave.  I know it will not accept an answer file.  Does that mean that my hope of creating a batch file to make my life easier is in vain?    

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Batch File Q: Please Help Me!
« Reply #7 on: July 26, 2005, 02:48:07 PM »
I couldn't find any info on the net for your program. Does it not have any documentation about how to run it. I would think the program would take a command line parameter that points to the input file. You might be able to build a loop, processing each file thru your program.

If you could post how you run it from the command line, perhaps someone could find a solution.

Let us know. 8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

dosnovice

  • Guest
Re: Batch File Q: Please Help Me!
« Reply #8 on: July 26, 2005, 02:57:14 PM »
Okay, this is my last post of the day 'cause it's time to get on the subway and go home.  The program runs like this, step by step:
rmovave [starts program]
imput file?
output file?
sampling rate?
time constant to use?
signal ground?
start at what sec?
end at what sec?
I hope this answers your question.  I desperatly want to build that loop your talking about.  I spent the entire day answering these prompts over and over again.  All answers were the same with the exception of input and output file (obviously).  Thanks for your help.

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Batch File Q: Please Help Me!
« Reply #9 on: July 26, 2005, 06:55:15 PM »
Since the program is calling for data, all that needs to be done is to redirect the STDIN device (the keyboard) to a file. And a little smoke and mirrors of course ;D

Code: [Select]

@echo off
for /f "tokens=1-2 delims=. " %%a in ('dir /b /s path\*.dat') do (
     echo %%a.%%b       > answer.dat
     echo %%a.out      >> answer.dat
     echo samplingrate >> answer.dat
     echo timeconstant >> answer.dat
     echo signalground >> answer.dat
     echo startsec     >> answer.dat
     echo endsec       >> answer.dat
     path\rmovave < answer.dat
     )


How does it work?

1) gets a list of all the input files; the *.dat is the filter. (please tell me they're in the same directory)
2) sets up responses to program queries
3) runs program using redirected STDIN device, the answer.dat file

Output files will have same name as input file with a .out extension. Change if need be.

You need to fixup path\ and *.dat Make sure the path\ points to the input and output files and the filter matches your input file extensions; Also put real values for sampling rate thru endsec and fixup the path\ to the rmovave program.

With any luck all your input files will be processed with no input from you.

Good luck. 8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

merlin_2

  • Guest
Re: Batch File Q: Please Help Me!
« Reply #10 on: July 26, 2005, 08:05:27 PM »
Not to nick sidewinders thunder but i found this ,and its up to you!>http://www.softtreetech.com/i24x7.htm

dosnovice

  • Guest
Re: Batch File Q: Please Help Me!
« Reply #11 on: July 27, 2005, 08:50:48 AM »
Thanks guys for all your help!  We're almost there, except for one problem.  My program (rmovave) doesn't like having the path ahead of the input and output file.  How can I alter sidewinder's code so that the path doesn't show up in the answer.dat file the batch file creates? I need to do this for both input and output.  You guys have been so helpful. Thanks again so much!  

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Batch File Q: Please Help Me!
« Reply #12 on: July 27, 2005, 09:08:51 AM »
Remove the /s switch from the dir command:

Code: [Select]

for /f "tokens=1-2 delims=. " %%a in ('dir /b path\*.dat') do (


If you are running the batch file from the directory where the input files and the rmovave is located, you don't need any path\ info. The output files will also be placed in the same directory.

Hope this helps. 8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

dosnovice

  • Guest
Re: Batch File Q: Please Help Me!
« Reply #13 on: July 27, 2005, 09:23:55 AM »
IT WORKS!  Thanks so much sidewinder, you have no idea how much this helps me, along with everyone else in my office.  I'm going to try and add on to this file so that it will run the output through two more programs.  I'll probally have problems with that too, but now I have somewhere to start from.  Thanks again!

dosnovice

  • Guest
Re: Batch File Q: Please Help Me!
« Reply #14 on: July 27, 2005, 10:49:14 AM »
One more question.  I'm trying to apply the same code to use with two more programs.  The programs are sample (downsamples the sample rate of the file ie. from 500Hz to 5Hz) and int2drl (converts files to double realtime precision format).  I've created batch files to do this as a test (eventually I want to combine them all into one batch file) and I've run into some old problems.  I wrote the code out exactly the same, changed the values for input, changed the filter, and gave the answer file a new name.  Yet it doesn't want to use the .dat file to answer the program prompts as it so nicely does for rmovave.  Any ideas?  Thanks again!

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Batch File Q: Please Help Me!
« Reply #15 on: July 27, 2005, 01:50:52 PM »
By using variable file names, one combined batch file is preferable to separate batch files.

Do the other two programs request data from the keyboard the same as rmovave or do you pass data along the command line? Do they all use the same input file or is output of one the input to the next? How do you want the programs to run, one file thru all 3 programs then start the second...or all files thru one program, then all files thru 2nd program, then all files thru 3rd program?

Let us know. 8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

dosnovice

  • Guest
Re: Batch File Q: Please Help Me!
« Reply #16 on: July 27, 2005, 02:15:51 PM »
Thanks for getting back to me.  Yes, my ultimate goal is to have one batch file to run all three programs.  They go in this order:  Output from rmovave becomes input for sample.  Output from sample becomes input for int2drl and that's the end of it.  And yes, they requre prompts in the same way as rmovave. I guess it doesn't matter the batch file runs each file one by one or in chunks, whichever is easiest.  I created some new batch files using the same code you gave me for rmovave just to run as a test (these programs, especially rmovave, take a long time to do their thing).  Where I'm running into a problems is when the batch file plugs the answer.dat file back into the program to answer the prompts.  It doesn't work.  The answer.dat is created, I can call it up and look at it, but it won't plug into the program.  WHY?!!! I did everything the same. I've had two PHDs at the office look at it and they can't figure it out either.  My only though (whatever that's worth) is that it is something different about the programs (sample and int2drl). Help me sidewinder, your my only hope!
« Last Edit: July 27, 2005, 02:17:38 PM by dosnovice »

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Batch File Q: Please Help Me!
« Reply #17 on: July 27, 2005, 02:32:41 PM »
Please post one of the batch files you wrote. All things being equal, this might be very simple.
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

dosnovice

  • Guest
Re: Batch File Q: Please Help Me!
« Reply #18 on: July 27, 2005, 02:36:01 PM »
Here's the one for Int2drl:

@Echo off
for /f "tokens=1-2 delims=. " %%a in ('dir /b c:\sdsids\battest\*.rm5') do (
echo %%a.%%b > ansint.dat
echo %%a.mdb >> ansint.dat
echo 1 >> ansint.dat
c:\sdsids\battest\int2drl < ansint.dat
)

And here's the one for sample:

@echo off
for /f "tokens=1-2 delims=. " %%a in ('dir /b c:\sdsids\battest\*.rm') do (
echo %%a.%%b > anssam.dat
echo %%a.rm5 >> anssam.dat
echo 500 >> anssam.dat
echo 5 >> anssam.dat
c:\sdsids\battest\sample < anssam.dat
)

Sorry, I don't know how to make those code boxes you had, so the top line is cut in half.  Still, you get the idea.
« Last Edit: July 27, 2005, 02:37:37 PM by dosnovice »

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Batch File Q: Please Help Me!
« Reply #19 on: July 27, 2005, 03:49:33 PM »
I couldn't find any syntax problems with your files, and since Sample and Int2drl get input from the keyboard, the only thing I can suggest is to follow the files. After you run rmovave where do the output files (.rm) end up? Make sure the paths on the FOR statements point to the actual location of the files. If there are no values to pass to the %%a and %%b variables the batch file will crash and burn.

Let us know how you make out. 8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

dosnovice

  • Guest
Re: Batch File Q: Please Help Me!
« Reply #20 on: July 28, 2005, 09:41:42 AM »
I've checked the path and everything looks okay.  Both batch files get the files I need and create a correct answer file.  For some reason this answer.dat won't plug in answer the program prompts.  Could it be a problem with the programs I'm trying to run themselves?  The are prompted the same way as rmovave, through the keyboard.  I think I've really hit a wall here.  Any thoughts?  Anyone?

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Batch File Q: Please Help Me!
« Reply #21 on: July 28, 2005, 10:32:48 AM »
I am also puzzled. Unless your two programs have found a whole new way to implement a keyboard interrupt then input redirection should be transparent. If you do find a solution or explanation, please post it; it should be very interesting to read.

???
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

dosnovice

  • Guest
Re: Batch File Q: Please Help Me!
« Reply #22 on: July 28, 2005, 12:25:10 PM »
I'm completely stumped.  I think I've checked everyting and it still doesn't work.  The code is fine.  The path is fine.  The programs don't have anything different about the way they are prompted (all from the keyboard).  There is nothing I can think of to make this work.  Though, my knowledge of this kind of thing is admitedly pretty low.   ??? ???

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Batch File Q: Please Help Me!
« Reply #23 on: July 28, 2005, 01:06:02 PM »
I found this little piece of info on the net.

Quote
A Pascal program can be made to detect the redirections using
Interrupt 21Hex, function 44Hex, subfunction 00Hex

While this does nothing to help you out, it might explain your dilema. Sample and Int2drl may not be programmed to detect the redirection. Sorry, but you just may be SOL.

:-/
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

Octo

  • Guest
Re: Batch File Q: Please Help Me!
« Reply #24 on: June 09, 2020, 06:45:28 AM »
There's another question. I'm trying to use the same code as other programs. These programs are an example used to convert files from 500hz to 5Hz, I created a batch file as a quiz and eventually I want to include it in a batch file I have old problems.
12BET
I wrote the same code, changed the input value, changed the filter and gave the file an answer, the new name, but it did not want to use the data file to answer the program instructions because it responded very well. You have any idea, thank you again.