stdin

How to read from files in argv or stdin if none are given?

一世执手 提交于 2020-08-17 11:06:30
问题 I have a program that calculates a lottery tickets (this tickets are in a file.txt), and writes the winners tickets in another file. I have a subfunction called evaluate_tickets(file, lottery_numers, winner....) In shell I write: ./program arg1 arg2... (arg1, arg2 are text files i.e. file.txt) But now, I want to do ./program < file.txt . The problem is that I don't know how to send the parameter "file" of evaluate_tickets because I receive information by stdin. 回答1: Define a stream pointer

Python - How to parse argv on the command line using stdin/stdout?

喜夏-厌秋 提交于 2020-07-06 13:47:05
问题 I'm new to programming. I looked at tutorials for this, but I'm just getting more confused. But what I'm trying to do is use stdin and stdout to take in data, pass it through arguments and print out output results. So basically,on the command line, the user will input the and an argument. The arguments are: i = sys.argv [1] f = sys.argv [2] w = sys.argv [3] Then using if/else the program will execute some stuff based on which argument chosen above. i.e: On the command line the user will enter

Close the stdin of boost::process child

六月ゝ 毕业季﹏ 提交于 2020-06-27 23:22:48
问题 I'm trying to call a process with a string to its stdin, with Boost-1.64.0. The current code is : bp::opstream inStream ; bp::ipstream outStream; bp::ipstream errStream; bp::child child( command, // the command line bp::shell, bp::std_out > outStream, bp::std_err > errStream, bp::std_in < inStream); // read the outStream/errStream in threads child.wait(); The problem is that the child executable is waiting for its stdin EOF. Here child.wait() is hanging indefinitely… I tried to used asio: