[英]Writing a Shell Script that runs my program with inputs
Ok so I created my own shell, and I've tested it plenty on my own, but I need shell scripts that will run it and test it. 好的,所以我创建了自己的shell,并且已经对它进行了很多测试,但是我需要可以运行和测试它的shell脚本。
I've create a script which consist of this: 我创建了一个包含以下内容的脚本:
#!/bin/bash
echo "ls && echo dog" | ./a.out
However, all it does is print the command prompt "$" infinitely, and I have to force quit the program. 但是,它所做的只是无限地打印命令提示符“ $”,而我不得不强制退出程序。 therefore I am pretty sure my program does not like my script lol.
因此,我很确定我的程序不喜欢我的脚本。 My program works by using getline to capture the user input until they push <enter> and the boost library to tokenize the string and look for connector eg "||"
我的程序通过使用getline来捕获用户输入,直到他们按下<enter>并通过boost库对字符串进行标记并查找连接器(例如“ ||”)来工作。 "&&" ";"
“ &&”“;” and and so on, then run the commands.
依此类推,然后运行命令。 All of this is done in a while loop that loops until the user types exit and I close my program.
所有这些都是在while循环中完成的,直到用户类型退出并关闭程序为止。 Being as I am new to writing scripts I am sure I probably am not writing my script in the best of manners.
作为一个刚开始编写脚本的新手,我确信我可能不是以最好的方式编写脚本。 I created a simple program to ask for your age and then output it and this script method works for that, but being as my shell isn't as simple I am not surprised this scrip doesn't seem to work.
我创建了一个简单的程序来询问您的年龄,然后输出该脚本方法,该方法适用于该年龄,但是由于我的shell并不那么简单,所以我不惊讶此脚本似乎不起作用。
string user_input;
bool good = true;
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
while(good){
//command prompt
cout << "$ ";
//read in user input
getline(cin, user_input);
//tokenize user input
tokenizer tok(user_input);
//parse and execute commands inputed by user in string
//only exit while loop if user command is <exit> good = false
}
my shell works if I execute the program normally and I enter inputs into the program what I need is a shell script that I can use to run and test the program for me. 如果我正常执行程序,并且在程序中输入了输入内容,那么我的外壳程序将起作用,我需要的是一个外壳脚本,可以用来为我运行和测试该程序。 Ex.
例如 if I type ./script.sh in the standard linux shell it will run my script which will then execute my a.out and then test my own shell with a variety of commands Examples being ls echo ...
如果我在标准linux shell中键入./script.sh,它将运行我的脚本,然后执行我的a.out,然后使用各种命令测试我自己的shell例如ls echo ...
You should exit the shell when you reach EOF (End Of File). 到达EOF(文件结束)时,应该退出外壳。 Getline while return -1 in that case.
Getline在这种情况下返回-1。 I can't think of any other advice as you didn't provide any code, but this might resolve the infinite loop issue.
我没有其他建议,因为您未提供任何代码,但这可能会解决无限循环问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.