Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Simulating Enter key in .bat

Simulating Enter key in .bat

Simulating Enter key in .bat

We have some .exe files that reside on a windows box. We would like to automate them.  There is one problem, they need input parameters.  my task is to write DOS programs to do it. Now before you tell me that there are other scripts we should do that with i agree and suggested that to the powers that be,  unfortunately DOS is what they told me to use.

I define some variables as such:
set FIELD1=Y
set FIELD2=N
set FIELD3=N
echo.| set FIELD4
echo. |set FIELD5

This is how I pass the parameters. Fields 1-3 are pretty straight forward. However fields 4 and 5 need to press the enter key to continue running the .EXE.  The echo. | before the set is the latest thing I saw by googling.  When I google I come up with many ways to do this none of which worked all the way from it can't be done and to get some software package (technical services at my company says no) to the echo . | Any ideas would be welcome.  


RE: Simulating Enter key in .bat

If the only entry in FIELD4 and FIELD 5 is to be a Carriage Return, then you can try:

set FIELD4=chr(13)


Bob   morning

RE: Simulating Enter key in .bat

Tried that got the following message

chr(13) was unexpected at this time


RE: Simulating Enter key in .bat


Didn't seem like it should be so difficult ...

And you may not like it - I surely don't.

But the cost is free ...

I wonder if you weren't given this task as a test or challenge.

1. Create a text file using a hex editor.  I used HxD.  If you need one, it's at:  

2. Use the hex editor to make the contents of the file hex 0D.
Save this file somewhere that is accessible to anyone needed the Enter (Carriage Return) in a batch file.

3. Add the following to your batch file to load a variable.  I don't know how it works, but it seems to.

For this example, the text file is named CR.txt and the variable to load is FIELD4

FOR /F "tokens=1 delims=" %%A in ('CR.txt') do SET FIELD4=%%A echo %myVar%

If you try this, please advise if it works.

Bob   morning

RE: Simulating Enter key in .bat

Not sure about being tested I have written numerous .bat's. I have just never encountered one that needs a press enter to continue. When I put your code in it just opens the hex file it does not load the enter to the variable. I will keep working on it.  


RE: Simulating Enter key in .bat

Ok thanks I do have a few ideas left I will let you know


RE: Simulating Enter key in .bat

I just couldn't completely give up.

Try this:

set /a FIELD4=\x0D

Also, check to see if there are options available with programs requiring Enter.  I.E., I have used some that had parameter options for automated use.  Something like:

C:\path\someprog.exe /a

where the /a indicated to the program it was being run in automatic mode, like within a batch file.

Bob   morning

RE: Simulating Enter key in .bat

I think the issue is I am trying to feed an executable the enter code.  I am wondering if I need to simulate the enter code in the language of the .exe. I don't know what that is it was externally written.  


RE: Simulating Enter key in .bat

It's possible that feeding the enter code via parameter happens too quickly.

I.E., the parameter is read immediately upon program load rather than when the program is looking for it.

Usually, there are speedy replies here ...

Maybe the pro's are chuckling to themselves while we're trying to sort it out.

Good Luck!

Bob   morning

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close