Armen Tsirunyan
Armen Tsirunyan

Reputation: 132974

How to specify end of input in a batch file

I have a program x.exe it waits for an input from user and reads till end of file. I want to call it from a batch file.

x.exe My Text Goes Here and goes and goes and goes and how to say it ends?

When I run it, it seems as though x.exe is running, it has already consumed the string I gave it, but it is still pending for more input. How do I specify the EOF character in a batch file?

When I run it from console, I press Ctrl+Z to specify eof. How do I do the same with a bat file? Thanks.

Upvotes: 0

Views: 893

Answers (1)

Jon
Jon

Reputation: 16718

echo "My Text Goes Here and goes and goes and goes and how to say it ends?" | x.exe

The way you're doing it now doesn't actually send the text to your program as input, it passes them as command line arguments (the array of strings that is passed to your main function - it is char* argv[] that is argc elements long).

Use echo to print it to standard output, and then use the pipe to connect the standard output of echo to the standard input of your program.

Upvotes: 2

Related Questions