Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send text to standard input of a Windows console app

I am trying to write a .bat file to automate some shell commands. Most of the commands are easy and I can just put them into the batch file directly, but there is one command which instead of taking command line parameters, expects you to type in the options you want using "the standard input". I'm not exactly sure what that means. Can someone tell me how to do this? The text I would like to be entered is the contents of one of the files in the directory: "options.txt" which I want to concatenate with a variable inside the batch file "$(additionaloptions)".

Make sense?

like image 692
skb Avatar asked Jan 15 '10 23:01

skb


1 Answers

The usual way to do this in .bat files is to use echo to write a small text file, then redirect the text file to standard in of the command.

@echo foo > bar.txt
@echo if you need multiple lines >> bar.txt

the_cmd < bar.txt

In your specific example it would something like

copy myfile.txt bar.txt
@echo %variable% >> bar.txt

The fact that you are mention $(variable) suggests to me that this is a makefile rather than a batch file. for a makefile, theres a better way.

like image 194
John Knoeller Avatar answered Oct 11 '22 10:10

John Knoeller