I have a shell script that that has some questions that nee to be answered(Answers are in form of strings). I have to make another batch file that opens the shelll script and answers the questions automatically. the problem i am facing is that when i open the shell script on cmd using my batch file, i get stuck on the shell script. Any ideas on what commands i will need to input the answers automatically?
我有一个shell脚本,有一些问题需要回答(答案是字符串形式)。我必须创建另一个打开shelll脚本的批处理文件并自动回答问题。我面临的问题是,当我使用我的批处理文件在cmd上打开shell脚本时,我会陷入shell脚本。关于我需要什么命令自动输入答案的任何想法?
1 个解决方案
#1
1
Generically, you need to use either redirection with a temporary file, or a pipe.
通常,您需要使用临时文件或管道重定向。
I'll assume your controller batch file needs to provide three answers to script.bat.
我假设您的控制器批处理文件需要为script.bat提供三个答案。
Using Redirection
@echo off
>answers.txt echo answer1
>>answers.txt echo answer2
>>answers.txt echo answer3
call script.bat <answers.txt
del answers.txt
or you can use a single redirection if you use parentheses
或者,如果使用括号,则可以使用单个重定向
@echo off
>answers.txt (
echo answer1
echo answer2
echo answer3
)
call script.bat <answers.txt
del answers.txt
Using a Pipe
@echo off
(
echo answer1
echo answer2
echo answer3
) | script.bat
#1
1
Generically, you need to use either redirection with a temporary file, or a pipe.
通常,您需要使用临时文件或管道重定向。
I'll assume your controller batch file needs to provide three answers to script.bat.
我假设您的控制器批处理文件需要为script.bat提供三个答案。
Using Redirection
@echo off
>answers.txt echo answer1
>>answers.txt echo answer2
>>answers.txt echo answer3
call script.bat <answers.txt
del answers.txt
or you can use a single redirection if you use parentheses
或者,如果使用括号,则可以使用单个重定向
@echo off
>answers.txt (
echo answer1
echo answer2
echo answer3
)
call script.bat <answers.txt
del answers.txt
Using a Pipe
@echo off
(
echo answer1
echo answer2
echo answer3
) | script.bat